使用xib创建CollectionViewCell注意事项
2015-10-29 17:29
453 查看
项目中最近经常使用collectionView 但是系统的总是不满足要求,这时就需要我们自定义collectionView,根据不同的架构有不同的创建方式,我使用的是xib创建,那么问题来了:
- (void)awakeFromNib {
[_HLChoosePhotoActionSheetCollectionView registerClass:[HLChoosePhotoActionSheetCell class] forCellWithReuseIdentifier:@"HLChoosePhotoActionSheetCellID"];
}
在实例化方法中注册xib中的cell运行后,直接崩掉!抛出一下问题 找不到identifier标识的cell ,当时就蒙了,怎么会找不到呢?
后来研究才发现,原因在于注册cell的方法顺序错误,应该在
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
static NSString *HLChoosePhotoActionSheetCellIdentifier = @"HLChoosePhotoActionSheetCellID";
//在这里注册自定义的XIBcell 否则会提示找不到标示符指定的cell
UINib *nib = [UINib nibWithNibName:@"HLChoosePhotoActionSheetCell" bundle: [NSBundle mainBundle]];
[collectionView registerNib:nib forCellWithReuseIdentifier:HLChoosePhotoActionSheetCellIdentifier];
HLChoosePhotoActionSheetCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:HLChoosePhotoActionSheetCellIdentifier forIndexPath:indexPath];
[cell showDataWithImageName:@"weixin_app_icon"];
return cell;
}
这个代理方法里面进行注册自定义的cell。在运行,OK!跑起来了。
- (void)awakeFromNib {
[_HLChoosePhotoActionSheetCollectionView registerClass:[HLChoosePhotoActionSheetCell class] forCellWithReuseIdentifier:@"HLChoosePhotoActionSheetCellID"];
}
在实例化方法中注册xib中的cell运行后,直接崩掉!抛出一下问题 找不到identifier标识的cell ,当时就蒙了,怎么会找不到呢?
后来研究才发现,原因在于注册cell的方法顺序错误,应该在
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
static NSString *HLChoosePhotoActionSheetCellIdentifier = @"HLChoosePhotoActionSheetCellID";
//在这里注册自定义的XIBcell 否则会提示找不到标示符指定的cell
UINib *nib = [UINib nibWithNibName:@"HLChoosePhotoActionSheetCell" bundle: [NSBundle mainBundle]];
[collectionView registerNib:nib forCellWithReuseIdentifier:HLChoosePhotoActionSheetCellIdentifier];
HLChoosePhotoActionSheetCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:HLChoosePhotoActionSheetCellIdentifier forIndexPath:indexPath];
[cell showDataWithImageName:@"weixin_app_icon"];
return cell;
}
这个代理方法里面进行注册自定义的cell。在运行,OK!跑起来了。
相关文章推荐
- hdoj--2546--饭卡
- 【JSOI2010】【BZOJ1821】Group 部落划分 Group
- Android 关于接口回调原理的解析
- dubbo——管理员指南(顶)
- 关于linux服务安全监测防御及其流量监控
- Activity启动过程全解析
- linux 下连接mysql服务器
- textbox之间简单的四则运算
- iText5报表_页眉与页脚
- 1014 我的C语言文法定义与C程序推导过程
- NoSQL世界里的Memcached和redis缓存的区别
- 添付ファイルを固定した名前アップロードする
- 第9周项目2-对称矩阵压缩存储的实现与应用(2)
- DOM访问与修改
- AFNetworking发送成功,接收不到数据问题
- linux环境下GXL软件的安装
- 使用Loader实时查询本地数据库用法
- iOS 公司开发者账号申请
- 中文短信编码(二)
- saltstack 安装nginx