標籤:
源地址:http://fann.im/blog/2012/09/11/uitableview-optimization-notes/
Hacking Week 技術總結最後一篇,記一下 UITableView 效能最佳化需要注意和改進的地方。
- 網狀圖片非同步載入,SDWebImage。
- 文字直接 drawInRect/drawAtPoint 繪製,參考 ABTableViewCell,AdvancedTableViewCells。
- 本地圖片也可以直接繪製,或者用 CALayer 來添加顯示。
- cell 重用機制。
- cell 內容盡量避免透明效果。
- 如非必要,減少 reloadData 全部 cell,只 reloadRowsAtIndexPaths。
- 如果 cell 是動態行高,計算出高度後緩衝。tableView 會在載入的時候把全部 cell 的高度通過
heightForRowAtIndexPath: 都計算出來,即使 cell 還沒有展示。
- 如果 cell content 的展示位置也不固定,第一次計算後也要緩衝。
- cell 高度固定的話直接用
cell.rowHeight 設定高度,不要再實現 tableView:heightForRowAtIndexPath: delegate.
- cell content 的解析操作(尤其是複雜的解析)非同步進行+預執行,解析結果要緩衝。
- 可以積極式載入需要的網路資源(圖片等),SDWebImagePrefetcher.
There are performance implications to using tableView:heightForRowAtIndexPath: instead of the rowHeight property. Every time a table view is displayed, it calls tableView:heightForRowAtIndexPath: on the delegate for each of its rows, which can result in a significant performance problem with table views having a large number of rows (approximately 1000 or more). via Apple Document
iOS 8:【轉】UITableView 效能最佳化筆記