在下面的代码中,我使用了每个单元格的单个单元格标识符,效果很好。
-(UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *identifier =[NSString stringWithFormat:@"ID_%d",indexPath.row];
UITableViewCell *cell = [self.tv dequeueReusableCellWithIdentifier:identifier];
if(cell==nil)
{
UITableViewCell *cell = [self.tv dequeueReusableCellWithIdentifier:identifier];
cell.textLabel.text=@"data";
}
return cell;
}
以下代码中的任何性能,内存或任何其他问题?
答案 0 :(得分:3)
如果您使用个人标识符,则不会重复使用这些单元格。每个UITableViewCell都会有所不同。
在您的代码中,如果cell == nil
,则再次调用deque..
。
如果没有带标识符的单元格,则必须分配新的UITableViewCell
。
答案 1 :(得分:2)
性能问题毫无疑问。单元格标识符的重点是表格视图可以快速重用现有单元格,而不是为每一行创建(并存储)新单元格。
细胞标识应该特定于细胞类型。如果您有一个包含三个“类型”单元格的表格视图,那么请使用三个标识。