I'm just starting to use the UICollectionView so bear with me!
How do I load a nib into the cell?
It seems I have to register the nib and class to be used, but this does not work.
Code:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
[collectionView registerClass:[CluelessSymbolCell class] forCellWithReuseIdentifier:@"Symbol cell"];
[collectionView registerNib:[UINib nibWithNibName:@"CluelessSymbolCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"Symbol cell"];
CluelessSymbolCell *cell = (CluelessSymbolCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"Symbol cell" forIndexPath:indexPath];
CluelessClue *clue = [clueManager clueForIndexPath:indexPath];
[cell.backgroundImageView setImage:[UIImage imageNamed:[clue.imageNames objectAtIndex:0]]];
return cell;
}
It turns out my nib file had the default view controller in it (which was hidden) as well as my custom cell - doh!
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