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

 }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章