I have this in my view controller:
- (UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CellSubclass *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];
cell.dataObjects = data;
return cell;
}
In my CellSubclass.m I have:
- (id) initWithFrame:(CGRect)frame
{
// You can call initWithFrame: method here as our base constructor of the UIView super class
self = [super initWithFrame:frame];
if (self)
{
// call functions that need access to data but data is nil
}
return self;
}
So in the lifecycle of my view controller, the CellSubclass gets called immediately before the data is ready. Is there a function like viewWillAppear or something that I can pass the data too? How can I call a function from my view controller other than initWithFrame? Can I pass the data in other ways?
Thanks.
It sounds better to use your own configure method for cell in cellForItemAtIndexPath.
- (UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CellSubclass *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier"
forIndexPath:indexPath];
cell.dataObjects = fetchedMUtableArray[indexPath.row];
[cell somethingConfiguringMethods];
return cell;
}
UICollectionViewCell does not have something like that, but that is a subclass of UIView and that one has didMoveToSuperview. I use it in production for some specific cases, but anyway it helps for some fast debugging also.
https://developer.apple.com/documentation/uikit/uiview/1622433-didmovetosuperview
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