Uitableview 性能優(yōu)化 -- 加載不在屏幕范圍的cell

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

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容