ios 中registerClass的作用
来源:互联网 发布:淘宝被扣12分能恢复吗 编辑:程序博客网 时间:2024/04/28 17:28
ios 中registerClass使用注意事项:
registerClass 什么时候需要写,什么时候不需要写?
ios6之后API发生了变化,ios6之前完全不用写,ios6之后根据情况
registerClass是和cell联系在一起的 ,UITableViewCell或UICollectionViewCell
在ios6之前重用cell是这样的
重用方法是这个:
dequeueReusableCellWithIdentifier:
具体实现为:
static NSString *cellIdentifier = @"cellIdentifier";UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier;}
每次重用队列里如果没有可重用的cell,就手动新创建一个cell,
而在ios6以后增加了另一个 寻找重用cell的方法:
dequeueReusableCellWithIdentifier:forIndexPath:
具体实现为
static NSString *cellIdentifier = @"cellIdentifier";[self.tableView registerClass:[MyCell class] forCellReuseIdentifier:cellIdentifier];UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
这个函数的实现是这样的如果在重用队列里面没有 可重用的cell就自动创建一个cell,无需人工alloc init
可见,如果项目至支持ios6之后,第二种写法比较简洁.而且ios6出现的collectionView 只有后一种写法。
1 0
- ios 中registerClass的作用
- ios 注册cell 中 registerClass 和registerNib 的区别
- iOS开发 UITableview的registerClass : forCellReuseIdentifier:的用法
- iOS自定义UITableViewCell registerNib: 与 registerClass: 的区别
- IOS开发 自定义TableViewCell(registerNib:与registerClass:的差异)
- ios UITableViewCell(registerNib: 与 registerClass: 的区别)
- TableView registerClass的用法
- ios 中appdelegate的作用
- RegisterClass
- registerClass
- RegisterClass
- 关于RegisterClass的注册位置
- 关于RegisterClass的注册位置
- 关于RegisterClass的注册位置
- registerNib: 与 registerClass: 的区别
- UITableView的registerClass forCellReuseIdentifier释义
- ios中类变量的作用范围
- iOS程序中main函数的作用
- postgreSQL常用命令
- android 电池(一):锂电池基本原理篇
- android CursorLoader用法介绍
- 网易电面实习生(成功拿到offer)
- Numpy随记
- ios 中registerClass的作用
- BlockingQueue深入分析
- ubuntu NVIDIA显卡驱动安装
- PHP会话处理相关函数介绍
- spring事务管理配置
- Android中TextToSpeech的简单使用
- 对于MJRefresh刷新后往上偏移问题的解决
- 双向队列---Deque与LinkedBlockingDeque深入分析
- 函数式宏定义与普通函数