標籤:
一、.重用cell
在資料來源方法中,在可見的頁面重複繪製
OC方法中- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;SWIFT方法override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
因此 ,可以在該方法中做一些處理操作
OC處理操作 static NSString * ReusedCellID = "ReusedCellID"; UITableViewCell * cell = tableView.dequeueReusableCellWithIdentifier( ReusedCellID, forIndexPath: indexPath)swift的處理操作 private let ReusedCellID = "ReusedCellID" let cell = tableView.dequeueReusableCellWithIdentifier( ReusedCellID, forIndexPath: indexPath)
這樣,就可以防止cell無限的被建立,重用cell
二、cell的圖片非同步載入
當設定圖片非同步載入之後,cell 的圖片就放在了子線程中執行,但是,如果此時下滑,也會出現卡頓的現象
解決辦法:
非同步下載,在以下兩個方法中下載圖片、
// 當結束拖拽的時候- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate// 減速的時候- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
具體操作:
//擷取可見部分的對象NSArray *visiblePaths = [self.tableView indexPathsForVisibleRows];for (NSIndexPath *indexPath in visiblePaths){ //擷取的dataSource裡面的對象,並且判斷載入完成的不需要再次非同步載入 <code>}同時在cell繪製中也做限制- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{ if (self.tableView.dragging == NO && self.tableView.decelerating == NO) { //開始非同步載入圖片 <code> }
}
三、盡量少用透明的圖層
內部的渲染機制
【IOS開發】UITableView的效能最佳化