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]; } }
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!