问题
I'm facing a strange issue while scrolling my UICollectionView. It's showing a blank view without any cells in it.
It strangely hides my cell or removes my cell, I don't know, but I'm unable to find any solution.
I have tried these solutions from SO:
1st : Tried to create custom class of UICollectionViewFlowLayout and do as directed with all different methods but unable to solve my issue.
2nd : Tried below method to reattribute and recalculate my cell size :
-(BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds
{
return YES;
}
Links I followed :
Que1: UICollectionView's cell disappearing
Que2: UICollectionView items disappear when scrolling with my own UICollectionViewFlowLayout subclass
Please guide me whats wrong with simple collectionview with custom cell.
Reference Image :
Before Scroll:
After Scroll:
回答1:
Here I am answering my own question.
As I am stuck since last 2 days for this issue hope some one get help if any one get same issue like me.
As I am using CollectionViewController and add that Controller view into my current using controller so its disappearing my collection view cell.
Reason : due to
ARCreleasing thatdelegate&datasourceconnection and that collecton view can't able to get cell while I am scrolling from top to bottom.
Solution:
I solve this problem by 2 ways.
1st : Create that CollectionViewController in my current VC not in Service & JSON Parser class due to delegate & datasource connection loss.
Most Important part in below code is addChildViewController by this it will not releasing delegate connection and works as expected.
UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
CardListViewController *objCardListViewController = [mainStoryBoard instantiateViewControllerWithIdentifier:@"CardListViewController"];
objCardListViewController.view.frame = CGRectMake(0, 0,self.cardMainView.frame.size.width, self.cardMainView.frame.size.height);
[self.cardMainView addSubview:objCardListViewController.view];
[self addChildViewController:objCardListViewController];
but as per my requirement I needed this collection view at many places so I need to generalize this collection view.
So I go for 2nd Way which is ContainerView with add child controller and I connect this CollectionViewController with container view so I can use it as many places where I need this list.
Strange but true.
Hope this will help someone if facing same issue.
Thanks & Happy Coding.
来源:https://stackoverflow.com/questions/41592580/cell-disappearing-after-scrolling-2-3-times-in-uicollectionview