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

2018-01-03  本文已影响0人  xukunluren

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

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

上一篇 下一篇

猜你喜欢

热点阅读