I have a UICollectionView that is displayed by clicking a table cell within a navigation controller. So the UICollectionView is the second screen in the navigation controller's stack.
Cells showed up fine in the collection view when I registered a nib and created the cell via the UICollectionViewCell class. But once I try to create a subclass for the cell, the collection view just shows up as a black screen. My project can be found here. Link to Project in Dropbox
To subclass the UICollectionViewCell, I did the following:
Registered the custom class with the cell's reuse identifier, within viewDidLoad of the view controller that displays the collection view.
[self.collectionView registerClass:[CustomCollectionViewCell class] forCellWithReuseIdentifier:@"cvCell"];
Created an instance of the custom cell in "collectionView: cellForItemAtIndexPath:"
CustomCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cvCell" forIndexPath:indexPath];
From what I've read, that should do it! But the collection view is showing up blank, can anyone help??
I checked your code. You have done perfectly. Collection view with cells is showing correctly, but you cannot see that since you are not setting any of the property of the cell. Just check by setting background color of the cell in cellForItem
cell.backgroundColor = [UIColor redColor];
If you are done everything in nib then you need to register nib instead of class. use registerNib
instead of registerClass
. If you are registering class you have to do everything programmatically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With