I've got a collection view that's set up as a single horizontal row of cells. It's throwing the following constraint error (I'm using AutoLayout):
The behavior of the UICollectionViewFlowLayout is not defined because the item height must be less than the height of the UICollectionView minus the section insets top and bottom values, minus the content insets top and bottom values.
I've Googled around and looked on SO, and everyone suggests that it's fixed by simply overriding the UIScrollViewDelegate methods:
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
// iPhone 6+ device width handler
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's still not working. It appears to be gawking at the fact that the cell height is taller than it's container, even though I'm setting the cell to the same hight as the container. Here's the rest of the error:
The relevant UICollectionViewFlowLayout instance is UICollectionViewFlowLayout: 0x7fa6943e7760, and it is attached to MyCollectionView: 0x7fa69581f200; baseClass = UICollectionView;
frame = (0 0; 375 98); clipsToBounds = YES; autoresize = RM+BM; layer = CALayer: 0x7fa694315a60; contentOffset: {0, 0}; contentSize: {0, 134}
Setting the cell manually to a drastically smaller size (e.g. size - 50.0
seems to work, but why can't I set the cell size to the same height as its container?