在寫代碼的過程中,可能一個cell的高度過高導致第二個cell無法在屏幕中顯示璧榄,而這第二個cell在原有的機制下加載會產(chǎn)生卡頓咖楣,在嘗試其他優(yōu)化方法后,可以使用以下方法 對未在屏幕中展示的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