1.不要一次性創(chuàng)建所有的subview,而是需要時才創(chuàng)建.合理使用 懶加載
比如NSDateFormatter 和 NSCalendar這種高開銷對象
static NSDateFormatter *cachedDateFormatter = nil;
+ (NSDateFormatter *)cachedDateFormatter {
if (!dateFormatter) {
dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat: @“YYYY-MM-dd HH:mm:ss”];
}
return dateFormatter;
}
2.不要頻繁的刷新頁面,能刷新1行cell最好只刷新一行,盡量不要使用reloadData.
//刷新一組
NSIndexSet* indexSet = [[NSIndexSetalloc]initWithIndex:1];
[self.myTableViewreloadSections:indexSetwithRowAnimation:UITableViewRowAnimationAutomatic];
//刷新一行
NSIndexPath*indexPath=[NSIndexPathindexPathForRow:1inSection:0];
[self.myTableViewreloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationNone];
3.選擇正確的集合
NSArray,使用index來查找很快(插入和刪除很慢)
字典,使用鍵來查找很快
NSSets,是無序的,用鍵查找很快,插入/刪除很快
4.重用
UITableView和UICollectionView復(fù)用
5.緩存所有需要的
服務(wù)器相應(yīng)結(jié)果的緩存(圖片)
復(fù)雜計算結(jié)果的緩存(UITableView的行高)
重復(fù)使用的下拉框省市區(qū)等