I'm implementing a custom UICollectionViewCell, and I want to know how to send model data to it so the data can be used to initialize the subviews of the cell.
I register my MyCollectionViewCell by doing..
[self.collectionView registerClass:[MyCollectionViewCell class] forCellWithReuseIdentifier:@"MyCell"];
and in the following method, I do...
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
MyCollectionViewCell* cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:@"MyCell" forIndexPath:indexPath];
The problem I'm facing is, when a cell isn't in the reuse queue, it initializes a new cell by calling the initWithFrame method (which the documentation confirms should happen). However, I have a custom init method in my MyCollectionViewCell class, which is...
-(id) initWithFrame:(CGRect)frame withData: (NSDictionary*) data;
I want my custom initialize method to be called instead. How would I do that? I'm not using any nibs and I'm doing everything programmatically.
If there's no way, and I must use the initWithFrame method instead, how else can I pass model data to my MyCollectionViewCell so that I can initialize the subviews with that data?
Thanks!
How about [cell initData:data] right after you dequeue it? You probably need to re-init the data on dequeued cells, anyway.
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