当前位置:首页 > 通信资讯 > 正文

IOS collectionViewCell防止复用的两种方法

collectionView 防止cell复用的方法一:

?
1 2 3 4 5 6 7 8 9 //在创建collectionView的时候注册cell(一个分区) UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@“cell" forIndexPath:indexPath]; for (UIView *view in cell.contentView.subviews) { [view removeFromSuperview]; }

collectionView 防止cell复用的方法二:

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 //在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]; } }

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

如果您对该产品感兴趣,请填写办理(客服微信:xiaoxiongyidong)

为您推荐:

发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。