I'm getting the error ...
*** Assertion failure in -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:], /SourceCache/UIKit/UIKit-2372/UICollectionView.m:2249
When trying to display a UICollectionView.
The lines causing it are...
static NSString *CellIdentifier = @"Cell";
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
Error happening on the dequeue.
There are no other errors so I'm struggling to know where to begin with this.
Can anyone shed light on this?
Make sure that if you use the
registerNib:
method:that ALSO in the nib file, when you select the top-level collection reusable view, use the attributes inspector, and make sure the
Identifier
is set to the same value you are passing in to thewithReuseIdentifier:
parameter.Replace
with
I got this crash on iOS 9 only (iOS 10/11 are working fine).
I had no custom subclass of a Flow Layout but setting the
headerReferenceSize
on the existing one directly. So in Interface Builder with Section Header enabled I got this crash, without the checkmark everything works fine and the headers are being displayed correctly, since I set the size in code.You need to register like below:
Been reading the docs (should possibly have done this first :) )
Anyway, the collectionView I am using is within a separate xib file (not a storyboard) and from the docs...
Thanks
I had the same problem. Here's how I solved it.
Move
[self.pictureCollectionView registerNib:[UINib nibWithNibName: bundle:nil] forCellWithReuseIdentifier:reuseID]
to be in
- (void)viewDidLoad
,rather than method
- (void)awakeFromNib
.