我是靠谱客的博主 机智小白菜,这篇文章主要介绍IOS collectionViewCell防止复用的两种方法,现在分享给大家,希望可以做个参考。

IOS collectionViewCell防止复用的两种方法

collectionView 防止cell复用的方法一:

//在创建collectionView的时候注册cell(一个分区)

UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@“cell" forIndexPath:indexPath];

  for (UIView *view in cell.contentView.subviews) {

    [view removeFromSuperview];

  }



collectionView 防止cell复用的方法二:

//在cellForItem方法中注册cell(多个分区)

 NSString *identifier=[NSString stringWithFormat:@"%ld%ld",(long)indexPath.section,(long)indexPath.row];

  

  [collect registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:identifier];

  

  UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];

  

  for(id subView in cell.contentView.subviews){

    

    if(subView){

      

      [subView removeFromSuperview];

    }

    

  }

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

最后

以上就是机智小白菜最近收集整理的关于IOS collectionViewCell防止复用的两种方法的全部内容,更多相关IOS内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(167)

评论列表共有 0 条评论

立即
投稿
返回
顶部