滚动我的 UICollectionView
时遇到一个奇怪的问题.它显示一个空白 View ,其中没有任何单元格。
它奇怪地隐藏了我的手机或移除了我的手机,我不知道,但我找不到任何解决方案。
我已经从 SO 尝试了这些解决方案:
第一名:试图创建 UICollectionViewFlowLayout
的自定义类并按照指示使用所有不同的方法,但无法解决我的问题。
第二名:尝试以下方法重新归因和重新计算我的单元格大小:
-(BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds
{
return YES;
}
我关注的链接:
查询1:UICollectionView's cell disappearing
问题2:UICollectionView items disappear when scrolling with my own UICollectionViewFlowLayout subclass
请指导我使用自定义单元格的简单 Collection View 有什么问题。
引用图片:
滚动前:
滚动后:
最佳答案
在这里,我正在回答我自己的问题。
因为我在这个问题上被困了两天。
当我使用 CollectionViewController
并添加 Controller
查看我当前使用的 Controller ,因此它正在消失我的收藏 View 单元格。
Reason: due to
ARC
releasing thatdelegate
&datasource
connection and that collection view can't able to get cell while I am scrolling from top to bottom.
解决方案:
我以两种方式解决这个问题。
第一名:创建
CollectionViewController
在我目前的VC
不在服务中和 JSON
解析器类由于 delegate & datasource
连接丢失。以下代码中最重要的部分是
addChildViewController
这样它就不会释放委托(delegate)连接并按预期工作。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.
所以我选择第二种方式
ContainerView
添加子 Controller ,我连接这个CollectionViewController
使用容器 View ,因此我可以在需要此列表的许多地方使用它。奇怪但真实。
如果遇到同样的问题,希望这会对某人有所帮助。
谢谢和快乐的编码。
关于ios - 在 UICollectionView 中滚动 2-3 次后单元格消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41592580/