Reputation: 6795
I have a custom UICollectionViewCell
, and I dequeue it from my view controller by registering it like so
[self.calendarView registerNib:[UINib nibWithNibName:NSStringFromClass([DayCell class]) bundle:nil] forCellWithReuseIdentifier:dayCell];
and then dequeueing like so
cell = [collectionView dequeueReusableCellWithReuseIdentifier:dayCell forIndexPath:indexPath];
My question is, which UICollectionViewCell
init method would allow me to access the cell's reuseIdentifier
? Both awakeFromNib
and initWithCoder:
methods get called, however, both log (null)
for self.reuseIdentifier
.
This is a problem, because I want to use the same UICollectionViewCell
class but with different reuseIdentifier
s to achieve slightly differently looking cells, and I want to perform the styling once upon init. For instance, a cell with dayCellDisabled
reuseIdentifier
would have a label of lighter colour.
Upvotes: 2
Views: 2590
Reputation: 6795
One solution I found that works is to not override any init or awake methods, but configure my reusable view in this method instead
- (void)didMoveToSuperview {};
Apparently, this method gets called only once when the view is being added to its handler. I tested and confirmed this is the case for a reusable UICollectionViewCell
that is added to a UICollectionView
.
Upvotes: 2