我注意到当滚动到视图外时单元格被取出内存,然后在滚动到视图时添加回内存。
我得到了性能原因,但由于我的表只有几个单元格不可见,有没有办法关闭这个缓存功能?
答案 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。