Friday, 13 September 2013

Where to determine the height of a dynamically sized UICollectionViewCell?

Where to determine the height of a dynamically sized UICollectionViewCell?

I'm using UICollectionViewFlowLayout. My cells contain UILabels that
differ in height (number of lines).
It seems that the best way to get the cell height would be in the subclass
of UICollectionViewCell, because that is where I set the layout and have
access to intrinsic size of my views, BUT:
collectionView: layout: sizeForItemAtIndexPath: is called BEFORE the
collectionView: cellForItemAtIndexPath: delegate method, which means that
I need to know the cell height before I have the actual cell.
Everything I came up with so far seems too complicated, like starting with
fixed cell height, referencing actual height and reloading the data again
before the view loads. Is there a better way to do this?

No comments:

Post a Comment