Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading a nib into a UICollectionViewCell

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;
}
like image 580
Adam Carter Avatar asked Jan 17 '26 17:01

Adam Carter


1 Answers

It turns out my nib file had the default view controller in it (which was hidden) as well as my custom cell - doh!

like image 59
Adam Carter Avatar answered Jan 20 '26 23:01

Adam Carter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!