Create UICollectionViewCell subclass with xib [duplicate] Create UICollectionViewCell subclass with xib [duplicate] ios ios

Create UICollectionViewCell subclass with xib [duplicate]


Make sure the cell on the .xib file know what's the type of the cell.

Select the cell on your interface builder

enter image description here

and then on the identity inspector

enter image description here

Subsequently associate your labels with your properties. (I think you already did that)

Then I'd recommend to verify if you already loaded the .xib file on your cellForItemAtIndexPath: method

NSString *identifier = @"MyCell";        static BOOL nibMyCellloaded = NO;    if(!nibMyCellloaded)    {        UINib *nib = [UINib nibWithNibName:@"MyCell" bundle: nil];        [cv registerNib:nib forCellWithReuseIdentifier:identifier];        nibMyCellloaded = YES;    }


You can find the answer in this document UICollectionView adding UICollectionCell.

Only UICollectionView inside StoryBoard have UICollectionViewCell inside. If use XIB, create a new XIB with CellName.xib, add CollectionViewCell to it, specify name of UICollectionView custom class. After that use registerNib.Sample code: https://github.com/lequysang/TestCollectionViewWithXIB