简体   繁体   English

在UICollectionView上禁用单元重用

[英]Disable cell reuse on UICollectionView

I am using a UICollectionView in my app with gesture recognizers on the individual cells which allow the user to "slide open" the cell to reveal more data underneath. 我在我的应用程序中使用UICollectionView,在单个单元格上使用手势识别器,允许用户“滑开”单元格以显示下面的更多数据。

The problem is, I am reloading the data in the CollectionView very often; 问题是,我经常在CollectionView中重新加载数据; as the app receives updates once every 3 seconds or so. 因为应用程序每3秒钟左右收到一次更新。 This results in unwanted behavior with the collectionview cells being reused while a cell is in the process of being slid. 当细胞处于滑动过程中时,这会导致不需要的行为,同时可以重复使用集合视图单元。

The user will start to slide a cell, the app will receive an update, reloadData, and a different cell will start receiving the gesture instead, and begin sliding. 用户将开始滑动单元格,应用程序将接收更新,reloadData,并且不同的单元格将开始接收手势,并开始滑动。

I have tried disabling the app's updates while the slide is occurring, but that caused other complications within the app, so I am wondering if there is a way to disable the cell reuse, (I will only have 20 cells max, so I don't think there would be a large drop in performance). 我已经尝试在幻灯片发生时禁用应用程序的更新,但这导致了应用程序内的其他复杂情况,所以我想知道是否有办法禁用单元格重用,(我最多只有20个单元格,所以我不喜欢我认为性能会大幅下降)。

Thank you! 谢谢!

Why don't you use a flag like needsReload and set it, if new data is available. 如果有新数据,为什么不使用needsReload这样的标志并设置它。 After a slide you check for that flag and reload the collectionView, if needed? 在幻灯片后,检查该标志并重新加载collectionView,如果需要的话? Is this not working? 这不起作用吗?

If you don't want cell reusing, just use a default scrollView and put all your views in it!? 如果您不想重复使用单元格,只需使用默认的scrollView并将所有视图放入其中!

Disabling reuse is simple. 禁用重用很简单。 Just don't use the dequeueReusableCell method. 只是不要使用dequeueReusableCell方法。 Instead just alloc, init your cells. 而只是分配,初始化你的细胞。 I would be careful of the performance and memory implications of doing so though... 尽管如此,我会小心这样做的表现和记忆含义......

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

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