collectionViewCell防止複用的兩種方法

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 classforCellWithReuseIdentifier:identifier];

    

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

    

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

        

        if(subView){

            

            [subView removeFromSuperview];

        }

        

    }


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章