简体   繁体   中英

UICollectionView not to reuse cell

I have many cells with differ identity value. such as "baseball cell" "football cell"and "AD cell". 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?

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

If collection view reload the "AD cell" each time when it off-screen then visible again. And I stop the animation and release it when reloading. the user may have no chance to see the last of AD picture. So I need a way to stop the reusing just for AD cells

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. Do not use the dequeueReusableCellWithReuseIdentifier or dequeueReusableSupplementaryViewOfKind .But All memory management ,you should care.

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.

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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