源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

IOS collectionViewCell防止复用的两种方法

  • 时间:2021-08-17 20:01 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:IOS collectionViewCell防止复用的两种方法
[b]IOS collectionViewCell防止复用的两种方法[/b] [b]collectionView 防止cell复用的方法一:[/b]
//在创建collectionView的时候注册cell(一个分区)

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

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

    [view removeFromSuperview];

  }



[b]collectionView 防止cell复用的方法[/b][b]二:[/b]
//在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];

    }

    

  }

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部