Reputation: 899
I have a collectionView whose scroll direction is horizontal. It has only one line and its cell spacing is 16.0px. So i set its collectionViewLayout
to a custom layout named UICollectionViewLeftAlignedLayout
subclass of UICollectionViewFlowLayout
:
UICollectionViewLeftAlignedLayout *layout = [[UICollectionViewLeftAlignedLayout alloc] init];
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
layout.minimumInteritemSpacing = 16.0;
_myCollectionView.collectionViewLayout = layout;
_myCollectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
But when i scroll the collectionView, some cells of it disappeared. So weird! I have tried every solution i can find from google.com
, unfortunately did not work for me. I fix it and post the solution as a answer below.
Upvotes: 1
Views: 2207
Reputation: 899
I have fixed it !
I replace the custom UICollectionViewLeftAlignedLayout
with native UICollectionViewFlowLayout
just like this:
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
[layout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
_myCollectionView.collectionViewLayout = layout;
_myCollectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
And I set the cell spacing through storyboard(also you can set them through the layout's propery):
Then i run the project again , the UICollectionViewCell DO NOT DISAPPEAR anymore.
Upvotes: 2