UICollectionView doesn't contain UICollectionViewCell in IB UICollectionView doesn't contain UICollectionViewCell in IB xcode xcode

UICollectionView doesn't contain UICollectionViewCell in IB


I can't tell you why it does not work, but for me the subclass approach from this blog post solved the problem:

http://www.adoptioncurve.net/archives/2012/09/a-simple-uicollectionview-tutorial.php

here is a short summary:

  • create a new class MyViewCell which extends UICollectionViewCell and create properties, actions, outlets and methods as needed.

@interface MyViewCell : UICollectionViewCell

  • create a View (xib file) with a Collection View Cell as its root object (and delete the object which is created by default).
  • in the attributes set the custom class of this Collection View Cell to your extended class MyViewCell (instead of the default UICollectionViewCell).
  • in the attributes under Collection Reusable View define an Identifier, e.g. myCell, you will need this later to register your call.
  • go back to your custom class and modify the inithWithFrame method to load and use your created view.

    - (id)initWithFrame:(CGRect)frame {    self = [super initWithFrame:frame];    if (self)    {      // Initialization code      NSArray *arrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"CVCell" owner:self options:nil];     if ([arrayOfViews count] < 1) { return nil; }     if (![[arrayOfViews objectAtIndex:0] isKindOfClass:[UICollectionViewCell class]]) { return nil; }     self = [arrayOfViews objectAtIndex:0];   }   return self;}
  • then you can register this class to be used by the collectionView with

[self.collectionView registerClass:[MyViewCell class] forCellWithReuseIdentifier:@"myCell"];


It's been a while since the question has been asked but I faced the same issue lately.

Eventually, I found the answer here.

In short:

  • You cannot drag and drop a UICollectionViewCell into a UICollectionView if you are in a .xib file. This is only possible in a storyboard.

  • The workaround is to create a .xib file for your custom cell and to register the cell manually using:

    [self.collectionView registerClass:[CollectionViewCell class] forCellWithReuseIdentifier:CELL_ID];


Define your cell view in a separate nib file. The view must be of type UICollectionViewCell or a subclass.

Then, you must register the nib with your collection view:

- (void)viewDidLoad{    UINib *cellNib = [UINib nibWithNibName:@"MyNib" bundle:nil];    [self.collectionView registerNib:cellNib forCellWithReuseIdentifier:@"cell"];}