Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error could not dequeue a view of kind UICollectionElementKindCell

Taking first plunge with collection views and am running into this error:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'could not dequeue a view of kind: UICollectionElementKindCell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'

The code is very simple, as shown below. I can't for the life of me figure out what it is that I'm missing.

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath]; cell.backgroundColor = [UIColor whiteColor];  return cell; } 

The collection view controller was created using a nib and the delegates & datasources are both set to file's owner.

View Controller's header file is also really basic.

@interface NewMobialViewController_3 : UICollectionViewController <UICollectionViewDataSource, UICollectionViewDelegateFlowLayout> @end 
like image 909
Anti-Dentite Avatar asked Feb 25 '13 01:02

Anti-Dentite


1 Answers

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.

like image 75
jrturton Avatar answered Sep 16 '22 22:09

jrturton