UICollectionView Layout Issue

2019-02-01 15:30发布

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

13条回答
Melony?
2楼-- · 2019-02-01 16:11

What caused this for me was that I was trying to set my cells to the size of the superview rather than the size of the UICollectionView. Simply replaced the superview frame with the UICollectionView frame.

查看更多
Summer. ? 凉城
3楼-- · 2019-02-01 16:15

Be sure to set the right autoresizing mask for UICollectionView and UICollectionviewcell. This fixed my problem for iPhone 4 Simulator

查看更多
淡お忘
4楼-- · 2019-02-01 16:16

I found that, using storyboards, you have to go into the storyboard and click on the overall View Controller (the view should be highlighted in blue) and go to the Attributes Inspector (the fourth tab on the right side of the screen) and unchecking the "Under Top Bars", "Under Bottom Bars", and "Under Opaque Bars." This cleared up the issue for me, and it cleared it for my coworkers as well.

查看更多
劳资没心,怎么记你
5楼-- · 2019-02-01 16:17

If you're loading a collectionView via a container view + UICollectionViewController, you may have set a height constraint on the container view which is constraining the height of the collection view itself. In my case, I found the collectionView.contentSize was taller than the constraint I had set on my container view.

Obviously this is a bit of an edge case but just in case you have a similar setup, I figured I'd add this comment.

查看更多
Melony?
6楼-- · 2019-02-01 16:25

I've been having some issues when the using a collection view to present full screen view controllers.

Basically at run time, it'll ask for the size of the item and simply return the size of the collection view:

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    return self.collectionView.frame.size;
}
查看更多
迷人小祖宗
7楼-- · 2019-02-01 16:25

For me I am using AKPickerView inside of a custom UIView which was giving me a slew of warnings like the ones mentioned here. All I did to eliminate the warnings was to Un-Check the box called 'AutoResize Subviews' in the Attributes Inspector for my custom UIView. That silenced the warnings so hard, I thought my logger stopped working.

enter image description here

查看更多
登录 后发表回答