【发布时间】:2010-01-13 21:43:29
【问题描述】:
我想用我的 UITableView 做一些非常简单的事情:我想将一个 UIActivityIndicatorView 添加到一个部分的标题视图中,并让它在我想要的时候动画或消失。
我使用 tableView:viewForHeaderInSection 将 UIActivityIndicatorView 添加到标题视图没有问题:
- (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 是我的控制器类的属性。 我在 viewDidLoad 方法中分配它:
- (void)viewDidLoad
{
(...)
activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(200, 10, 25, 25)];
}
这样我可以随时向它发送消息(例如 -startAnimating 或 -stopAnimating)。 问题是,一旦我滚动 tableView,activityIndicator 就会消失(我猜是因为 tableView:viewForHeaderInSection: 方法被第二次调用)。
我怎样才能将 activityIndicatorView 添加到部分的标题视图中,并且之后仍然能够向它发送消息? (当然,当我向下滚动时,activityIndicator 不会消失)
非常感谢!
【问题讨论】:
标签: iphone uitableview