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]; } }
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!