iOS 开发 解决UICollectionView的多组头部视图样式不一样复用时发生错乱问题
2016-12-21 18:40
357 查看
UICollectionView用起来比UITableView麻烦多了,如何解决多组头部视图复用时出现的错乱问题就很关键
头部视图有几种样式就注册几种头部视图
头部视图的代理方法中所做的判断处理
头部视图有几种样式就注册几种头部视图
// 防止cell和头部视图复用出现错乱 [collectionView registerClass:[WOCOHomeSelectTypeCell class] forCellWithReuseIdentifier:@"selectTypeCell"]; [collectionView registerClass:[WOCOHomeDisplayCell class] forCellWithReuseIdentifier:@"displayCell"]; [collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headerSelectType"]; [collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headerDisplay"];
头部视图的代理方法中所做的判断处理
// 返回每一组的头部或尾部视图 - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { // 1.定义重用标识 static NSString *ID; if (indexPath.section == 0) { ID = @"headerSelectType"; } else { ID = @"headerDisplay"; } UICollectionReusableView *reusableView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:ID forIndexPath:indexPath]; if (indexPath.section == 0) { // 网络加载 --- 创建带标题的图片轮播器 // 防止复用时反复创建对象 if (self.cycleScrollView == nil) { self.cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, KUIScreenWidth, 180) delegate:self placeholderImage:nil]; self.cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentRight; self.cycleScrollView.currentPageDotColor = [UIColor whiteColor]; // 自定义分页控件小圆标颜色 [reusableView addSubview:self.cycleScrollView]; // --- 模拟加载延迟 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ self.cycleScrollView.imageURLStringsGroup = self.imagesURLStringArr; }); } } else { // 防止复用时反复创建对象 if (self.lineView == nil) { UIImageView *lineView = [[UIImageView alloc] init]; lineView.backgroundColor = [UIColor blackColor]; self.lineView = lineView; [reusableView addSubview:lineView]; [lineView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.mas_equalTo(reusableView.mas_centerY); make.left.mas_equalTo(reusableView.mas_left).offset(10); make.height.mas_equalTo(20); make.width.mas_equalTo(3); }]; } // 防止复用时反复创建对象 if (self.tipLabel == nil) { UILabel *tipLabel = [[UILabel alloc] init]; tipLabel.text = @"定制精选"; tipLabel.textColor = [UIColor blackColor]; self.tipLabel = tipLabel; [reusableView addSubview:tipLabel]; [tipLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.mas_equalTo(reusableView.mas_centerY); make.left.mas_equalTo(self.lineView.mas_right).offset(10); }]; } } return reusableView; }
相关文章推荐
- 详解iOS 滚动视图的复用问题解决方案
- ios软件开发 解决删除cell视图遮挡删除按钮的问题
- iOS 滚动视图的复用问题解决方案
- iOS 开发之navigationController下子类视图发生位移的解决方法
- iOS 滚动视图的复用问题解决方案
- iOS 解决使用Cell的复用导致视图重叠的问题
- iOS项目开发实战——制作视图的平移动画以及解决移动异常问题
- [置顶] iOS 滚动视图的复用问题解决方案
- iOS 滚动视图的复用问题解决方案
- iOS 滚动视图的复用问题解决方案
- IOS开发问题解决之限制UITextField输入特定位数小数时,Done按钮失效
- 【iOS-Cocos2d游戏开发之七】在cocos2d中添加/删除系统组件,并解决View设置透明会影响View中的其他组件的问题!【11月28日更新解决添加组件Cocos2d动画停止播放的BUG】
- 打开键盘遮住View的问题解决方法-IOS开发
- 【iOS-Cocos2d游戏开发之十】添加粒子特效并解决粒子系统特效与Layer之间的坐标问题;
- 【iOS-Cocos2d游戏开发之十八】解决滚屏背景/拼接地图有黑边(缝隙)/动画播放出现毛边以及禁止游戏中自动锁屏问题!【2011年12月18日补充】
- IOS开发问题解决之UIAlertView调用UIActionSheet后灰色背景一直存在
- 打开键盘遮住View的问题解决方法-IOS开发
- 打开键盘遮住View的问题解决方法-IOS开发
- 【iOS-Cocos2d游戏开发之十八】解决滚屏背景/拼接地图有黑边(缝隙)以及禁止游戏中自动锁屏问题!
- 【iOS-Cocos2d游戏开发之十】添加粒子特效并解决粒子系统特效与Layer之间的坐标问题;