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. git之简单入门及操作~

    看了bili的教程,https://www.bilibili.com/video/av23853294?from=search&seid=3300012850779227291 特此整理下. ...

  2. Nearest Common Ancestors POJ - 1330 (LCA)

    Nearest Common Ancestors Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 34657   Accept ...

  3. HDU 6156 回文 数位DP(2017CCPC)

    Palindrome Function Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 256000/256000 K (Java/Ot ...

  4. SpringMVC controller接收的中文参数乱码

    CharacterEncodingFilter只对POST请求有用,GET请求的需要对你运行的tomcat 目录conf/server.xml文件中<Connector connectionTi ...

  5. Java基础知识回顾(一):字符串小结

    Java的基础知识回顾之字符串 一.引言 很多人喜欢在前面加入赘述,事实上去技术网站找相关的内容的一般都应当已经对相应知识有一定了解,因此我不再过多赘述字符串到底是什么东西,在官网中已经写得很明确了, ...

  6. 1026: [SCOI2009]windy数(数位dp)

    1026: [SCOI2009]windy数 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 9016  Solved: 4085[Submit][Sta ...

  7. 3282: Tree(LCT)

    3282: Tree Time Limit: 30 Sec  Memory Limit: 512 MBSubmit: 2249  Solved: 1042[Submit][Status][Discus ...

  8. setTimeout相关整理

    setTimeout里面函数有无双引号的区别 双引号中的作用域不捕捉局部变量,不用双引号包着的是捕捉局部作用域 var a = function(){ alert(1111) } function a ...

  9. MySQL基础9-主键约束、外键约束、等值连接查询、一对一和多对多关系

    1.主键约束和外键约束 外键约束 * 外键必须是另一表的主键的值(外键要引用主键!) * 外键可以重复 * 外键可以为空 * 一张表中可以有多个外键! 概念模型在数据库中成为表 数据库表中的多对一关系 ...

  10. Couchbase I

    Couchbase第一印象(架构特性) 面向文档 保存的字节流总有一个 DOCUMENT ID(Object_ID) 高并发性,高灵活性,高拓展性,容错性好 面向文档的集群存储系统 每个文档用一个唯一 ...