1)头视图和尾部视图的添加
UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headerView" forIndexPath:indexPath];

UICollectionReusableView *footerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footerView" forIndexPath:indexPath];

2)内嵌(需求就是UICollectionView没有像Tableview一样的TabHeaderView),想要制造一个

contentInset

3)没有注册
[_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headerView"];
[_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footerView"];
2.使用UICollectionView遇到的复用问题

1)头视图的使用
for (UIView *view in headerView.subviews) {
[view removeFromSuperview];
}

for (UIView *view in footerView.subviews) {
[view removeFromSuperview];
}

2)cell的复用

KnowledgeBasePopCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"KnowledgeBasePopCell" forIndexPath:indexPath];

3.使用UICollectionView不走代理的问题

1)item尺寸计算错误

2)禁止使用0.01这种尺寸

//每个item之间的间距
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{

return 0.01;
}

//定义每个Section 的 margin
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{

return UIEdgeInsetsMake(0.01,0.01,0.01,0.01);
}

上述两个是不走-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

3)在window上添加view,view上添加UICollectionView,是不走-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{

使用各种手势冲突判断解决方法,但是都没有效果

是UICollectionViewCell视图?
是UICollectionView类?
都不能捕捉到点击事件

解决方法:
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{

if ([touch.view isDescendantOfView:self.collectionView]) {
return NO;
}
return YES;
}

4。使用UICollectionView组头也可以悬停

UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
//header
flowLayout.sectionHeadersPinToVisibleBounds = YES;
//footer
flowLayout.sectionFootersPinToVisibleBounds = YES;

问题:这仅在iOS9中才支持这种设置

by:ml

使用UICollectionView遇到的各种坑的更多相关文章

  1. 记一次UICollectionView中visibleCells的坑

    记一次UICollectionView中visibleCells的坑 项目的要求是这样的 其实也是一个轮播图,而已,所以依照轮播图的实现原理,这里觉得也很简单,还是利用UICollectionView ...

  2. UICollectionView 如何定制每个Cell的Size

    最新用UICollectionView遇到挺多坑,差点让我废寝忘食了,虽然UICollectionView 逼格比UITableView高,但是真正想定制起来,特别是刚开始是用,真麻痹的到处都是坑,弄 ...

  3. iOS - UICollectionView 瀑布流 添加表头视图的坑

    UICollectionView 瀑布流 添加表头视图的坑 首先是,需求加了个头视图在顶部,在collectionView中的头视图跟TableView的不一样,TableView的表头只要设置tab ...

  4. UICollectionView cellForItemAtIndexPath 方法不走

    在storyboard 中 UICollectionView cellForItemAtIndexPath not called 被坑了好久,各种问题点查找,终于解决了 解决办法: self.auto ...

  5. 手把手教你使用UICollectionView写公司的项目

    在很多app中都有这样通用的页面,一直没有机会使用UICollectionView,只是简单的看过他的使用方法.今天公司美工出图,使用了他,并且遇到了好多的坑.记录一下过程,不确定使用的方法是不是最优 ...

  6. iOS 之UICollectionView 开发步骤 之 OC

    说起来容易做起来难. 那么我就不说了,来做吧.这就是我的style. 鉴于现在的主流还是OC,那么示例程序还用OC来写,后续补写Swift程序,这里先占个坑. 废话不多说,下面开发步骤来了: 1. 创 ...

  7. ios 适配iOS11&iPhoneX的一些坑

    前阵子项目开发忙成狗,就一直没做iOS11的适配,直到XcodeGM版发布后,我胸有成竹的在iPhoneX上跑起项目,整个人都凉透了...下面总结一下我遇到的坑,不是很全面,日后补充. 导航栏 导航栏 ...

  8. 关于collectionview布局的坑

    不知道写了多少次collectionview,步了很多坑,现在看来虽然达到了自己想要的结果,却不知道其中所以然.还是总结一下,免得再走弯路: 场景是这样的,我要定制一个显示选择图片的排列,想要实现横向 ...

  9. Xcode11.1 踩坑备忘录

    Xcode11.1 踩坑备忘录(mac系统10.15) 1 .环信ChatDemo2.0报错 这是环信ChatDemo2.0报错 NSInteger numberOfBeforeSection = [ ...

随机推荐

  1. Codeforces Round #461 (Div. 2) C. Cave Painting

    C. Cave Painting time limit per test 1 second memory limit per test 256 megabytes Problem Descriptio ...

  2. 水题:HDU-1088-Write a simple HTML Browser(模拟题)

    解题心得: 1.仔细读题,细心细心...... 2.题的几个要求:超过八十个字符换一行,<br>换行,<hr>打印一个分割线,最后打印一个新的空行.主要是输出要求比较多. 3. ...

  3. [Poj3133]Manhattan Wiring (插头DP)

    Description 题目大意:给你个N x M(1≤N, M≤9)的矩阵,0表示空地,1表示墙壁,2和3表示两对关键点.现在要求在两对关键点之间建立两条路径,其中两条路径不可相交或者自交(就是重复 ...

  4. 第 8 章: 模块, 包与分发---Word

    第八章: 模块, 包 与 分发 描述: 大型Python程序以模块和包的形式组织.另外,Python标准库中包含大量模块.本章详细介绍模块和包系统.还将提供有关如何安装第三方模块和分发源代码的信息. ...

  5. 笔记-算法-hash以及hashlib使用

    算法-hash和hash表以及hashlib使用 1.      简介 1.1.    hash Hash(散列/哈希),就是把任意长度的输入(预映射pre-image)通过散列算法变换成固定长度的输 ...

  6. Hive UDF开发指南

    编写Apache Hive用户自定义函数(UDF)有两个不同的接口,一个非常简单,另一个...就相对复杂点. 如果你的函数读和返回都是基础数据类型(Hadoop&Hive 基本writable ...

  7. iview框架 两侧弹框 出现第二层弹框 一闪而过的问题

    分析原因:寡人怀疑可能是,两层弹出框 采用的是一个开关值,发生了覆盖 解决方式 是在第二层弹框外套层计时器 源代码如下: 修改后为:

  8. 动态加载css,js

    function dynamicLoadCss(url) { var head = document.getElementsByTagName('head')[0]; var link = docum ...

  9. Eclipse配置Maven工具

    1.Maven安装,下载Maven二进行制文件: http://maven.apache.org/download.cgi 下载后解压,然后设置maven的bin目录到系统环境变量Path中,在cmd ...

  10. RESTful-rest_framework视图层-第三篇

    图书管理系统: 实现图书接口的增.删.改.查 方式一:普通的方式 views配置: #Book的增.删.改.查接口 class BookSerializer(serializers.ModelSeri ...