【发布时间】:2010-07-15 20:08:06
【问题描述】:
我在表格的每一行中添加一个活动指示器。问题是每次我滚动它时,它都会再次添加到覆盖前一个的单元格中。请让我知道在表格视图单元格中添加控件的最佳方法。
UIActivityIndicatorView *a;
// 自定义表格视图单元格的外观。
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
a = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[a startAnimating];
[cell.contentView addSubview:a];
// Configure the cell.
return cell;
}
【问题讨论】:
标签: iphone uitableview