1. xib的class要进行设置
2. 如果添加imageView注意不可以添加名为imageView会与系统自带的重名,导致一些相关属性设置了显示不正常。
3. 要记得去设置xib的identifier
4. 使用自定义cell时注写法:
static NSString *identifier = @"MyCell";
BOOL nibsRegistered = NO;
if (!nibsRegistered) {
UINib *nib = [UINib nibWithNibName:NSStringFromClass([MyCell class]) bundle:nil];
[tableView registerNib:nib forCellReuseIdentifier:identifier];
nibsRegistered = YES;
}
MyCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
cell.selectionStyle = UITableViewCellSelectionStyleNone; // 点击没有事件展示
注意
如果用注册方式,有可能Cell自定义元素为空,绑定不上
1.注册cell
[_menuCollectionView registerClass:[MenuCollectionViewCell class] forCellWithReuseIdentifier:cellId];
2.获取赋值
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
MenuItem *item = [self.menuArryobjectAtIndex:indexPath.row];
MenuCollectionViewCell *cell = (MenuCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellId forIndexPath:indexPath];
}
iOS自定义Cell实践
本文介绍iOS中使用自定义TableViewCell的方法,包括设置xib文件的class与identifier、避免与系统默认imageView名称冲突、注册自定义Cell及使用示例。同时提供解决自定义元素绑定不上问题的方案。
490

被折叠的 条评论
为什么被折叠?



