I have a collection view that is configured as one horizontal row of cells. It throws the following constraint error (I use AutoLayout):
The behavior of the UICollectionViewFlowLayout is undefined because the height of the element must be less than the height of the UICollectionView minus the upper and lower values of the sections, minus the upper and lower values of the content insert.
I have Googled and looked at SO, and everyone says that this is fixed simply by overriding the UIScrollViewDelegate methods:
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat multiplier = (screenWidth > kNumberOfCellsWidthThreshold) ? 4 : 3;
CGFloat size = screenWidth / multiplier;
return CGSizeMake(size, size);
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
return UIEdgeInsetsMake(0, 0, 0, 0);
}
But it still does not work. It looks like he repents that the height of the cell is higher than the container, although I set the cell to the same height as the container. Here is the rest of the error:
UICollectionViewFlowLayout UICollectionViewFlowLayout: 0x7fa6943e7760, MyCollectionView: 0x7fa69581f200; baseclass= UICollectionView;
frame = (0 0; 375 98); clipsToBounds = YES; autoresize = RM + BM; layer = CALayer: 0x7fa694315a60; contentOffset: {0, 0}; contentSize: {0, 134}
(, size - 50.0, , , , ?