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