I am using UICollectionView
using the flow layout.
I have made a custom UICollectionViewCell
for the same.
But on running the project the console keeps on throwing this error-
the behavior of the UICollectionViewFlowLayout
is not defined because:
the item height must be less that the height of the UICollectionView
minus the section insets top and bottom values.
I have made sure that the size of the cell is correct
Has anyone been able to resolve this issue. Thanks in advance.
Regards Nitesh
I have same issue
I solved this issue by checking the values in section Insets.And for fix cell size I have used below code.
None of the above fixes did it for me. I fixed it with this
If you are using storyboards and auto layout, debugging this kind of problems is really hard...
I had similar problem when trying to display UICollectionViewCell fullscreen on iPhone.
Most of the time issue is with the size of the cell set in
or directly on flowLayout.itemSize.
But... try:
And now try setting your auto layout constraints.
Good luck.
I just ran into the same error message, but for me the issue was that when I received new data from the api and tried to refresh my collectionView, the method that called
[collectionView reloadData]
wasn't calling it on the main thread.Hope this helps someone...
Had this issue myself a few times when trying to create collection views with fullscreen cells. My problem was caused by laying out for 4" screen in IB/Storyboard and specifying 320*568 for item size, but running in the simulator using 3.5" screen, which has a height of 480. The solution is to specify your item size in code with something like:
This ensures that the cell size is set correctly at runtime.
I know this is a very late reply, but I have also experienced this.
Inside my view controller, let's call it MyViewController I have a
UICollectionView
that is using customUICollectionViewCell
s. I'm implementing the method collectionView:layout:sizeForItemAtIndexPath where I am returning a item size that is dependent on the height of theUICollectionView
.MyViewController is made in a storyboard using autolayout to control the height of the
UIViewController
.The cells look fine when in portrait mode, but did not when in landscape mode.
I solved my issues by invalidating the
UICollectionViewLayout
of myUICollectionView
inside theviewWillLayoutSubviews
method.Earlier I had tried to invalidate the layout inside
willAnimateRotationToInterfaceOrientation:duration
, but it didn't work. The reason for this is probably that the sizes for all the views are not calculated yet, so we have to wait until autolayout has finished its magic. I refer to this SO thread.Update for Swift 4.0: