您的位置:首页 > 其它

collectionView 防止cell复用的方法

2017-05-24 09:33 609 查看
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];
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: