Xib自定义cell注意点, 解决Cell自定义控件为空情况

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];

 }

猜你喜欢

转载自huqiji.iteye.com/blog/2333667