UICollectionView's cell disappearing UICollectionView's cell disappearing ios ios

UICollectionView's cell disappearing


So, what did work?

1) Subclass UICollectionViewFlowLayout.

2) Set the flowLayout of my UICollectionView to my new subclass.

3) On the init method of the UICollectionViewFlowLayout subclass, set the orientation you want:

self.scrollDirection = UICollectionViewScrollDirectionHorizontal;

In my case it is Horizontal.

4) The important part:

-(BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds{   return YES;}

At this moment, I should theorise a bit, but honestly I don't have a clue.


The above answers didn't work for me, but after downloading the images, I replaced the code[self.myCollectionView reloadData] with [self.myCollectionView reloadSections:[NSIndexSet indexSetWithIndex:0]]; to refresh the collectionview and it shows all cells, you can try it.


None of the solutions given by anyone helped me in my custom layout that we need to have in our app.Instead, I had to do this: (And yeah, IT WORKS!!!)

- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect{    CGSize size = [self collectionViewContentSize];    rect.size.height = size.height*2;    NSArray *atrributes_Super = [super layoutAttributesForElementsInRect:rect];    return atrributes_Super;}

After all, UICollectionView is just looking for the attributes for the elements to be displayed in your screen's rect.