我想用我的UITableView做一些非常简单的事情:我想添加一个UIActivityIndicatorView到节的标题视图,并使其动画或消失,只要我想。如何在UITableView的节标题视图中访问UIActivityIndicatorView?
我没有任何麻烦,添加UIActivityIndicatorView使用的tableView头视图:viewForHeaderInSection:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 60.0)];
// create the title
UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(15.0, 12.0, 310.0, 22.0)];
headerLabel.text = @"some random title here";
[customView addSubview:headerLabel];
[headerLabel release];
// Add a UIActivityIndicatorView in section 1
if(section == 1)
{
[activityIndicator startAnimating];
[customView addSubview:activityIndicator];
}
return [customView autorelease];
}
activityIndicator是我的控制器类的属性。 我ALLOC它在viewDidLoad方法:
- (void)viewDidLoad
{
(...)
activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(200, 10, 25, 25)];
}
这样我可以发送消息给它(如-startAnimating或-stopAnimating)每当我想要的。 问题是activityIndicator一旦我滚动tableView就消失了(我想这是因为tableView:viewForHeaderInSection:方法被第二次调用)。
还有什么可以将activityIndicatorView添加到该部分的标题视图,并且仍然可以向其发送消息? (当然,当我向下滚动时activityIndicator不会消失)
非常感谢!
我不想在多个地方有一个activityIndicator,只有一个。 – nmondollot 2010-01-14 10:07:05
好吧,这就是它看起来像你试图做的,因为我无法想象任何其他原因继续添加子视图相同 – Nimrod 2010-01-14 16:39:56