My UICollectionView
cells don't get displayed on iOS6, because my delegate method cellForItemAtIndexPath
doesn't get called. I suspect because of this warning:
the behavior of the UICollectionViewFlowLayout is not defined because:
the item height must be less that the height of the `UICollectionView`
minus the section inset's top and bottom values.
I don't get the warning on iOS7, and all the cells display correctly there too.
I've set my collectionView
frame to height 270 in the .xib
and there are no insets defined.
I've set my cell height to 270 in the .xib
.
I can print out my collectionView
frame at runtime and it's 271.
Also, my collectionview
is actually inside a custom tableview
cell.
Any ideas? Thanks!
Try to set self.automaticallyAdjustsScrollViewInsets = NO
This was introduced in ios7 so you might want to wrap that with an ios version check, if you are supporting ios6 and below.
This fixed my problem! In my .xib
, setting my Collection View Size Cell Size to a smaller value.
My setup is that I have this collectionview
inside a custom tableview
cell and
I do return the height of my tableview
cell programatically (depending on the content). So it could be that my warnings had to do with my collectionview
not fitting inside the tableview
cell. So setting the initial collectionview
to a smaller value fixed it.
I was on the wrong path thinking that the problem was with my collectionview
and its colletionview
cell.
Maybe?
self.automaticallyAdjustsScrollViewInsets = NO
actually did the trick. it also resolved my issue in swift, where the cells of a horizontal flow layout had a frame top of -32 (???) and did not fit into the collection view properly.
I found that I had to manually set self.collectionView.collectionViewLayout.itemSize
in viewWillLayoutSubviews.
- (void)viewWillLayoutSubviews {
self.collectionView.collectionViewLayout.itemSize = CGRectMake(...);
}
Another possibility to generate the same trick would be to implement the methodcollectionView:layout:sizeForItemAtIndexPath:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With