简体   繁体   English

UICollectionView不重用单元格

[英]UICollectionView not to reuse cell

I have many cells with differ identity value. 我有许多具有不同标识值的单元格。 such as "baseball cell" "football cell"and "AD cell". 例如“棒球室”,“足球室”和“ AD室”。 The reusing of "baseball cell" "football cell" is ok for me. 对我来说,重用“棒球室”“足球室”是可以的。 but the "AD cell" has some animation effect on it, so I don't want to reload it if user scroll out. 但是“广告单元”上有一些动画效果,因此如果用户滚动出来,我不想重新加载它。

so, Is there a way to make collectionview not to reuse its cell? 因此,有没有一种方法可以使collectionview不重用其单元格?

Thanks! 谢谢!

Sorry, Update for clarify. 抱歉,请更新以澄清。

Here I got some cells types in collection view: 在这里,我在集合视图中找到了一些单元格类型:

  1. baseball cells : show baseball news 棒球室:显示棒球新闻
  2. football cells : show football news 足球室:显示足球新闻
  3. AD cells: show the AD_1.jpg -> AD_2.jpg -> AD_3.jpg... repeatedly 广告单元:重复显示AD_1.jpg-> AD_2.jpg-> AD_3.jpg ...

If collection view reload the "AD cell" each time when it off-screen then visible again. 如果收集视图每次在屏幕外重新加载“ AD单元”,则再次可见。 And I stop the animation and release it when reloading. 然后我停止动画并在重新加载时释放它。 the user may have no chance to see the last of AD picture. 用户可能没有机会看到最后一张AD图片。 So I need a way to stop the reusing just for AD cells 所以我需要一种方法来停止仅对AD单元的重用

Thanks. 谢谢。

You can cached your heavy cell object in other instance, just at the UICollectionViewDataSource collectionView: (UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath function, to load the cell by your self. 您可以在其他实例中缓存重单元对象,只需在UICollectionViewDataSource collectionView上: (UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath函数即可自行加载单元。 Do not use the dequeueReusableCellWithReuseIdentifier or dequeueReusableSupplementaryViewOfKind .But All memory management ,you should care. 不要使用dequeueReusableCellWithReuseIdentifierdequeueReusableSupplementaryViewOfKind 。但是,所有内存管理都应注意。

so in your case ,you cache the "AD cell" in the other cached class , in your UICollectionViewDataSource delegate just use the cached cell object from your cached class. 因此,在您的情况下,您将“ AD单元”缓存在另一个缓存的类中,在UICollectionViewDataSource委托中,只需使用缓存类中的缓存的单元对象即可。

Not enough information. 信息不足。

You generally want different cell identifies for different TYPES of cells (that have different structure) but the same ID for cells that have the same structure. 通常,您希望针对不同类型的单元(具有不同结构)使用不同的单元标识,但对于具有相同结构的单元则使用相同的ID。 That goes for animation as well. 动画也是如此。

Using multiple cells of the same type without recycling can cause lots of "memory churn", and is a bad idea. 使用多个相同类型的电池而不进行回收会导致大量的“内存搅动”,这是一个坏主意。

A cell won't be reused until it is off-screen, and at that point you should stop the animation. 除非在屏幕外,否则一个单元将无法重复使用,此时应停止动画播放。 Then you can fully prepare a recycled cell for reuse, including setting up a new animation. 然后,您可以完全准备一个回收单元以供重用,包括设置新动画。

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

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