UITableVIew的性能优化-重用原理
2015-07-14 22:40
405 查看
UITableVIew的性能优化:使用方法创建cell时,先优先从缓存池中找cell,找不到再创建新的cell,并且要绑定Identifer标示。
代码:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
// 定义一个静态的标识(只会初始化一次,内存分配一次)
static NSString *ID = @"c1";
// 优先从缓存池中去找cell
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:ID];
// 缓存池中找不到就创建一个新的cell,一定要绑定标示
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
}
}
代码:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
// 定义一个静态的标识(只会初始化一次,内存分配一次)
static NSString *ID = @"c1";
// 优先从缓存池中去找cell
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:ID];
// 缓存池中找不到就创建一个新的cell,一定要绑定标示
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
}
}
相关文章推荐
- [翻译] BAFluidView
- [Erlang_Question32]ibrowse流程及性能测试
- iOS Xcode 6报错:setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key v
- ueditor引入通用优酷视频
- Easyui Tab刷新
- UIScrollView 实现比例缩放
- UiAutomator喷射事件的源代码分析
- UIKit之浅析UIButton
- 关于继承UITableViewController若干问题
- Table的分割线偏移量设置 及其 UIEdgeInset详解
- iOS开发UI篇—UITabBarController简单介绍
- iOS --- 搜索框UISearchController的使用(iOS8.0以后替代UISearchBar + UISearchDisplayController的组合)
- NSArray, NSNumber, NSValue, NSSet, 数组排序
- UI基础(二)-图层
- IOS开发UI篇--一个侧滑菜单SlidingMenu
- UI_UItableView_AutoCell(自定义cell 高度)
- UI中一些名词的缩写
- 暑假选拔赛02 ---- Ysequence
- The method setPositiveButton(int, DialogInterface.OnClickListener) in the type AlertDialog.Builder i
- UI基础(一)