I have a UICollectionView (using flow layout) with cells using auto layout. To enable this I have set the estimatedItemSize to non zero values.
To trigger cellForRowAt I need to set a non zero height for the collection view. This can either be an explicit height constraint or an inherited height from the parent view.
However this seems to lead to a scenario where if the dynamic cell height calculated by auto layout is greater than the height of the collection view the error;
"... the item height must be less than the height of the UICollectionView..."
understandably occurs. What is the preferred solution to this? It seems like a catch 22 where I have to set a height of some value for cellForRowAt to be called but this value can potentially cause the above error.
The desired behaviour I'm attempting for is the collection view height to match the dynamic height of the cells (this is a horizontally scrolling collection view where each cell is "full screen").
UPDATE:
To clarify further here is are the steps are followed;
On view load, set the collection view height to a minimum, say 200. A non zero value is required here to trigger the data load.
Load the collection view data where cellForRowAt will initiate the creation of the cells. The cells will be sized using Autolayout.
If the sized cell height < 200, all is well.
If the sized cell height > 200, the flow layout error is logged as expected.
To resolve this, the cell needs to notify it's height in layoutSubviews. The collection view height is then adjusted to the new height if it is greater.
The net effect is I have a expanding collection view with a minimum height (of 200) and grows to the max height of the largest cell.