Subclass UICollectionViewCell not showing

I have a UICollectionView that is displayed by clicking a table cell in the navigation controller. Thus, UICollectionView is the second screen in the navigation controller stack.

The cells showed up in the collection view when I registered the tip and created the cell through the UICollectionViewCell class. But as soon as I try to subclass the cell, the collection view simply displays as a black screen. My project can be found here. Link to a project in Dropbox

To subclass UICollectionViewCell, I did the following:

  • Created .h and .m files for a subclass of UICollectionViewCell. A reference to this custom nib attribute pointer class.

enter image description here

  • Registered a custom class with a cell reuse identifier, in the viewDidLoad of the view controller, which displays the collection view.

    [self.collectionView registerClass:[CustomCollectionViewCell class] forCellWithReuseIdentifier:@"cvCell"];
    
  • A custom cell instance was created in "collectionView: cellForItemAtIndexPath:"

    CustomCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cvCell" forIndexPath:indexPath];
    

From what I read, it should be! But the collection view appears blank, can anyone help?

+5
source share
1 answer

I checked your code. You did fine. Viewing a collection with cells is displayed correctly, but you cannot see it, since you are not setting any property of the cell. Just check by setting the background color of the cell incellForItem

  cell.backgroundColor = [UIColor redColor];

nib, nib . registerNib registerClass. , .

+6

All Articles