collectionView 防止cell复用的方法
一:
//在创建collectionView的时候注册cell(一个分区)

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

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

        [view removeFromSuperview];

    }



二:

//在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];
        }
        
    }

 

相关文章:

  • 2021-06-02
  • 2021-11-12
  • 2021-11-22
  • 2021-07-13
  • 2021-08-30
  • 2022-02-24
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-05-30
  • 2021-09-09
  • 2022-01-19
  • 2022-12-23
相关资源
相似解决方案