一.具体报错的内容如下:
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: 0x7fce90e3d6c0>, and it is attached to <UICollectionView: 0x7fce918f2600; frame = (0 0; 375 200); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x7fce90e3ceb0>; layer = <CALayer: 0x7fce90e3bb70>; contentOffset: {0, 0}; contentSize: {0, 200}> collection view layout: <UICollectionViewFlowLayout: 0x7fce90e3d6c0>.
二. 原因分析
UICollectionViewFlowLayout的itemSize的宽或者高设置的有问题!它的size必须在父容器的范围之内!
父容器UICollectionView的高度为200,但是在设置itemSize高度的时候设置成250了。
self.flowLayout.itemSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, 250);
三.解决方法
将itemSize的高度也改的和父容器UICollectionView一致,即200.
self.flowLayout.itemSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, 200);