gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 04:38:04 24 4
gpt4 key购买 nike

我注意到,当滚动到 View 之外时,单元格会从内存中取出,然后在滚动到 View 中时又会添加回内存中。

我明白了这样做的性能原因,但由于我的表格只有几个单元格不在 View 中,有没有办法关闭此缓存功能?

最佳答案

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

这样,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 的数组。

关于ios - UITableView 滚动时不会重新排队/重绘单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10803396/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com