I have a collection view that contains different custom cells.
These cells contain different content that varies in size.
The cells are defined in the Storyboard, so no registering needed in code.
All i want to do now is change the size in the delegate method depending on the content:
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
id cellAtIndexPath = [collectionView cellForItemAtIndexPath:indexPath];
NSLog(@"The cell: %@", cellAtIndexPath);
...
e.g. calling sizeToFit methods and cumulating the sizes of the cells' subviews
...
}
The Method is called as expected for every cell, but cellAtIndexPath always returns NULL, no matter what i tried. So i am not able to access the cell object at the indexPath or its content view.
Any suggestions why i cannot access the cell object?
The collectionView:layout:sizeForItemAtIndexPath
method is called by the collection view's flow layout object. The layout is asking for the size of a cell at a time before the cells are added to the collection view. You will have to compute the desired cell size "on your own" and return it.
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