所以我有以下代码:
static NSString *CellIdentifier = @"RecommendationCell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TableViewCell"] autorelease];
}
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[indicator setCenter:CGPointMake(0, 15)];
[indicator startAnimating];
[indicator hidesWhenStopped];
UILabel *someLabel.........
UIView *containerView = [[UIView alloc] initWithFrame:CGRectZero];
[containerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
[containerView setAutoresizesSubviews:YES];
[containerView setBackgroundColor:[UIColor clearColor]];
[containerView addSubview:indicator];
[containerView addSubview:someLabel];
[containerView setFrameSize:CGSizeMake(indicator.frameWidth+self.loadingGeniusLabel_.frameWidth, 30)];
[containerView setCenter:CGPointMake(cell.contentView.center.x, 15)];
[cell.contentView addSubview:containerView];
[indicator release];
[containerView release];
return cell;
我的问题是,上面的代码是否高效/干净?我问的原因是因为如果我们得到的单元格来自可重复使用的平台,那么它会有 UIActivityIndicator 和必要的视图,对吗?我是否只需要在分配新单元格时才添加子视图(即:当单元格 == nil 时)?