Error could not dequeue a view of kind UICollectionElementKindCell Error could not dequeue a view of kind UICollectionElementKindCell ios ios

Error could not dequeue a view of kind UICollectionElementKindCell


From the UICollectionView documentation for the dequeue method:

Important: You must register a class or nib file using the registerClass:forCellWithReuseIdentifier: or registerNib:forCellWithReuseIdentifier: method before calling this method.


You need to use same identifier between the dequeueReusableCellWithReuseIdentifier's argument and the UICollectionViewCell's property.

UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CollectionViewCell" forIndexPath:indexPath];

identifier


Complementing what @jrtuton written... What you need is:

1) Register your nib file to "connect" it with your identifier:

//MyCollectionView.m- (void) awakeFromNib{ [self registerNib:[UINib nibWithNibName:@"NibFileName" bundle:nil]   forCellWithReuseIdentifier: @"MyCellIdentifier"];}

2) Use your identifier to load your custom cell from a nib:

//MyCollectionView.m- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath  *)indexPath {    MyCustomCollectionViewCell* cell = [cv dequeueReusableCellWithReuseIdentifier:@"MyCellIdentifier" forIndexPath:indexPath];}

3) Use always static NSString* to avoid the same identifiers again in your app.