Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the point of setting Reuse Identifier for Collection View Cell in Interface Builder?

Collection Reusable Views, including Collection View Cells (which is a subclass), have a field in Interface Builder called "Identifier" with prompt "Reuse Identifier".

However, you normally use it by registering it with the UICollectionView using the –registerNib:forCellWithReuseIdentifier: and –registerNib:forSupplementaryViewOfKind:withReuseIdentifier: methods, where you also specify a reuse identifier.

So then what's the point of setting one in Interface Builder? It seems to make no difference whether you set it there or not.

like image 709
user102008 Avatar asked Oct 20 '25 09:10

user102008


2 Answers

If you implicitly load a collection view from a storyboard you only have to do

UICollectionView *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:@"CollectionViewCell" forIndexPath:indexPath];

to get the cell. You don't need to call registerNib:. This only works if you set a reuse identifier.

like image 149
Sebastian Avatar answered Oct 21 '25 23:10

Sebastian


For NibCell (UICollectionView in a Nib) you must use registerNib:, that's only way. If you give your Cell in Nib a reuse identifier, this identifier must same in register so better leave it blank.

-Cell by Code: registerClass

-Cell in Nib(Xib) registerNib

-Cell in StoryBoard: don't register

One more answer of mine here

like image 26
LE SANG Avatar answered Oct 21 '25 22:10

LE SANG



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!