虚位以待(AD)
虚位以待(AD)
首页 > 软件编程 > IOS编程/Objective-C > IOS collectionViewCell防止复用的两种方法

IOS collectionViewCell防止复用的两种方法
类别:IOS编程/Objective-C   作者:码皇   来源:互联网   点击:

这篇文章主要介绍了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 collectionVi