美文网首页
Uitableview 性能优化 -- 加载不在屏幕范围的cel

Uitableview 性能优化 -- 加载不在屏幕范围的cel

作者: xukunluren | 来源:发表于2018-01-03 15:36 被阅读0次

在写代码的过程中,可能一个cell的高度过高导致第二个cell无法在屏幕中显示,而这第二个cell在原有的机制下加载会产生卡顿,在尝试其他优化方法后,可以使用以下方法 对未在屏幕中展示的cell进行预加载。
在viewDidAppear 或者 viewWillAppear

for (int i=0 ; i <10 ; i ++) {
[self tableView: self.myTableView cellForRowAtIndexPath: indexPath];
// give your indexpath for section=0 and row=i;
}

this line will Allocate all UITableViewCell but UITableView will discard them if they are not in Visiblecells.

To Do it add all your cells in NSMutableArray and in cellForRowAtIndexPath: load them from NSMutableArray.

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

详见:https://stackoverflow.com/questions/21053874/number-of-visible-cells-in-uitableview

相关文章

网友评论

      本文标题:Uitableview 性能优化 -- 加载不在屏幕范围的cel

      本文链接:https://www.haomeiwen.com/subject/hnwhnxtx.html