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

在写代码的过程中,可能一个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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容