UITableView在滚动时不会重新排队/重绘单元格

时间:2012-05-29 16:49:31

标签: ios uitableview

我注意到当滚动到视图外时单元格被取出内存,然后在滚动到视图时添加回内存。

我得到了性能原因,但由于我的表只有几个单元格不可见,有没有办法关闭这个缓存功能?

1 个答案:

答案 0 :(得分:1)

您可以尝试为每个索引路径使用不同的单元格标识符。

这样,UITableView将无法找到要出列的单元格,并且会提供一个新单元格。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    NSString * CellIdentifier = [NSString stringWithFormat:@"%d - %d", indexPath.row, indexPath.section];
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (!cell) cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

    return cell;
}

你也可以完全跳过排队/去队,并自己保留对它们的引用,然后在cellForRowAtIndexPath中返回它们:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    return [myCells objectAtIndex:indexPath.row];
}

myCells是一个包含UITableViewCell s。

的数组