关于UICollectionView那些年收到的警告
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.
The relevant UICollectionViewFlowLayout instance is <UICollectionViewFlowLayout: 0x101049460>, and it is attached to <UICollectionView: 0x1018f8a00; frame = (0 193; 414 117.667); clipsToBounds = YES; tag = 1000; gestureRecognizers = <NSArray: 0x17025a850>; layer = <CALayer: 0x170033b60>; contentOffset: {0, 0}; contentSize: {0, 0}> collection view layout: <UICollectionViewFlowLayout: 0x101049460>.
Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.
分析
当你收到这个警告的时候,你需要从三个方面分析一下你CollectionView
1.collectionViewCell和collectionView的内边距
如果你写了代理方法你就看看你下面这个方法
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
return UIEdgeInsetsMake(顶, 左, 底, 右);
}
和UICollectionViewFlowLayout的sectionInset方法同作用
2.UICollectionViewFlowLayoutd的itemSize的size
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return CGSizeMake(宽,高);
}
和UICollectionViewFlowLayout的itemSize方法同作用
3.你的UICollectionView的宽高
假设你的UICollectionView的高度是70,你的UICollectionViewFlowLayout的sectionInset的高度设置的也是是70,理所应当,你的UIEdgeInsetsMake的顶部和底部的距离就是0,如果你还强行设置一个大于o的高度,你就会报如题上面的警告。换成宽度也是一样
所以UICollectionView的宽高要设置合适才不会报警告