I'm getting this runtime error when I run my app in the simulator.
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'could not dequeue a view of kind: UICollectionElementKindCell with identifier PlayingCard - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
The line it crashes on is
UICollectionViewCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"PlayingCard"
forIndexPath:indexPath];
in the method
-(UICollectionViewCell*) collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath{}
As I understand it, the error means the indentifier "PlayingCard" doesn' match up with any of the identifiers of CollectionViewCells in in the CollectionView, but I have made sure that the identifier in the storyboard is identical.
Thanks for your help
Your Error tell detail about your problem
must register a nib or a class for the identifier or connect a prototype cell in a storyboard
If you create UICollectionViewCell class only by code, use register class in viewDidLoad for collectionView
[self.collectionView registerClass:[YourCell class] forCellWithReuseIdentifier:@"PlayingCard"];
If you create UICollectionViewCell by Xib, use registerNib
I think you forgot to specify class name for your Cell in storyboard
Here is a sample code of how to implement the cell with identifier for uicollectionview. I hope this helps out
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"YourIdentifier" forIndexPath:indexPath];
cell.backgroundColor = [UIColor whiteColor];
return cell;
}
Also there is a great tutorial on uicollectionview view in ray' web site that would help you understand the whole concept a bit more. Here is the link Tutorial
Edit:
The issue with your project crashing was indeed in the storyboard part. You did everything correctly but your cell was never connected. It was an easy fix. I sent you back the project and left you a bit comments in there too.
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