UITableViewCell性能優化

5.UITableViewCell性能優化緩存

1> 定義一個循環利用標識

static NSString *ID = @"C1";

2> 從緩存池中取出可循環利用的cell

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];

3> 若是緩存池中沒有可循環利用的cell

if (cell == nil) 
{
  cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
}

4> 覆蓋cell上面的數據

cell.textLabel.text = [NSString stringWithFormat:@"第%d行數據", indexPath.row];
相關文章
相關標籤/搜索