I ended up with a class method instead of an instance method:
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { return [CustomCell preferredSizeWithData:self.data[indexPath.row]; }
I made the Class method for the cell ... for this method, I provide the data that the actual instance will contain at the specified indexPath , and indexPath preferred size
I think that
CustomCell * cell = (CustomCell *)[collectionView cellForItemAtIndexPath:indexPath];
launches internally
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
and what we see is some kind of mechanism from Apple to prevent a loop cycle ... because the call is direct
CustomCell * cell = (CustomCell *)[self collectionView:collectionView cellForItemAtIndexPath:indexPath];
leads to a loop cycle.
source share