灵活式的collectionview的header
来源:互联网 发布:淘宝your highness 编辑:程序博客网 时间:2024/05/21 05:36
今天遇到了这么一个需求,有四个标签栏控制下面一个collectionview的刷新,其中点到第二个标签的时候需要显示header,照常规办法新建了一个类继承自UICollectionReusableView,然后collectionview注册了一下
[collectionView registerNib:[UINib nibWithNibName:@"EducationHeaderView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headID];
然后在collectionview的flowlayout里面设置一下header的尺寸headerReferenceSize = cgsizemake…,然后再数据源方法里面返回header,因为只需要第二个返回,所以加了判断
-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{ if ([kind isEqualToString:UICollectionElementKindSectionHeader]) { if (self.categoryView.currentIndex == 2) { return [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headID forIndexPath:indexPath]; }else{ return nil; } } return nil;}
运行然后程序崩溃。分析了一下,发现如果不给flowlayout设置header的size,数据源方法都不会走,可能与header的size有关,意思就是你既然给了size,就说明一定是有header,所以就不能返回空。所以就在标签切换的时候控制了一下header的size,问题解决。
UICollectionViewFlowLayout *layout = (UICollectionViewFlowLayout *)weakSelf.collectionView.collectionViewLayout; if (index == 2) { layout.sectionInset = UIEdgeInsetsMake(0, 15, 0, 15); layout.headerReferenceSize = CGSizeMake(SCREEN_WIDTH, 45); }else{ layout.headerReferenceSize = CGSizeZero; layout.sectionInset = UIEdgeInsetsMake(20, 15, 0, 15); }
0 0
- 灵活式的collectionview的header
- CollectionView Header的使用
- XZ_iOS之collectionView的header和footer的重用
- 关于在collectionView Header 中的button不可点击的问题
- collectionview通过设置contentInset方式添加表头Header,影响MJRefresh使用的解决方案
- CollectionView卡片式翻页的实现
- 多种Cell的CollectionView
- 关于collectionview的初始化
- CollectionView的使用
- collectionView的用法
- collectionView的注意事项
- 神奇的 collectionview
- collectionView的使用iOS
- iOS collectionView的使用
- collectionView的反弹效果
- 自定义重排的CollectionView
- collectionView的进阶
- iOS 分组的CollectionView
- 初识SSH框架
- AOP 那点事儿
- nifi中清空 Queue
- linux私房菜学习笔记—vim编辑器
- hdu 1392(求凸包周长)
- 灵活式的collectionview的header
- 能PIN通对方,对方却ping不通本机的问题
- iOS 延迟执行的方法总结
- 后缀数组倍增算法代码及解释
- Ubuntu解决MyEclipse/Eclipse Ctrl+Alt+Up/Down无法使用的问题
- Redis----sorted set数据类型操作
- js反选
- WikiTaxi_Importer_1.3.1 维基 离线数据库
- 或许我们做错了,但绝非一无是处