Question

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!

Was it helpful?

Solution 2

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?

OTHER TIPS

Try to set self.automaticallyAdjustsScrollViewInsets = NO

This was introduced in so you might want to wrap that with an version check, if you are supporting and below.

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 method
collectionView:layout:sizeForItemAtIndexPath:

I have the same issue, in my case the size of collectionCell in storyboard is 96x96 and also under -(CGSize)collectionView:layout:sizeForItemAtIndexPath:

the solution was removing this delegate:

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    UIEdgeInsets insets = {.left = 10, .right = 10, .top = 5, .bottom = 5};

    return insets;
}

And by the way this is under ios7, it's late but hope this will help some.. Cheers..

Set:

self.itemSize = CGSizeMake(1, 1);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top