Cell disappearing after scrolling 2 - 3 times in UICollectionView

浪子不回头ぞ 提交于 2019-12-07 08:23:30

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 ARC releasing that delegate & datasource connection 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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!