简体   繁体   English

UICollectionView单元格消失

[英]UICollectionView cell disappears

I am using collectionView in my iPad application. 我在我的iPad应用程序中使用collectionView。 I have used custom layout class which inherited UICollectionViewFlowLayout class. 我使用了继承UICollectionViewFlowLayout类的自定义布局类。

I am using horizontal scroll directional. 我正在使用水平滚动方向。 The problem is, whenever we use scroll for collection view, some times cell get disappear. 问题是,每当我们使用滚动进行集合视图时,有时候单元格会消失。 I debugged the code, and found that in data source method after creating cell, its hidden property get automatically ON. 我调试了代码,发现在创建单元格后的数据源方法中,其隐藏属性自动获得ON。

I tried using below line but its not working 我尝试使用下面的线,但它无法正常工作

   cell.hidden = NO  

I have below method also to invalidate layout on bound change. 我在下面的方法也使绑定更改的布局无效。

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

But still I am facing problem. 但我仍面临着问题。 Any solution on this ? 对此有何解决方案?

Thanks in advance. 提前致谢。

There is a known issue which may cause cells to disappear in UICollectionView. 有一个已知问题可能导致单元格在UICollectionView中消失 If their fix doesn't work for you, try PSTCollectionView , which is an open source replacement for UICollectionView. 如果他们的修复程序不适合您,请尝试PSTCollectionView ,它是UICollectionView的开源替代品。 If PSTCollectionView works, you should file a radar ticket to Apple. 如果PSTCollectionView有效,您应该向Apple提交雷达票。

In my project, the UICollectionViewCell disappear also ,the flowLayout i use is a custom layout named UICollectionViewLeftAlignedLayout . 在我的项目中,UICollectionViewCell也消失了,我使用的flowLayout是一个名为UICollectionViewLeftAlignedLayout的自定义布局。 Its scroll direction is horizontal .I debug the project again and again, have tried every solution i can find through google.com . 它的滚动方向是水平的。我一次又一次地调试项目,尝试了我可以通过google.com找到的每个解决方案。 All that did not work for me. 所有这些对我不起作用。

At the end ,i delete the UICollectionViewLeftAlignedLayout and use native UICollectionViewFlowLayout through: 最后,我删除了UICollectionViewLeftAlignedLayout并通过以下方式使用本机UICollectionViewFlowLayout

UICollectionViewFlowLayout *layout   = [[UICollectionViewFlowLayout alloc] init];
[layout setScrollDirection:UICollectionViewScrollDirectionHorizontal];

layout.scrollDirection               = UICollectionViewScrollDirectionHorizontal;
_collectionView.collectionViewLayout = layout;
_CollectionView.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. 然后我再次运行该项目,UICollectionViewCell不再消失。 Hope my case can help you . 希望我的案子可以帮到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM