第19月第2天 cellForItemAtIndexPath 返回空
1.
动画需要获取当前的 Cell ,下面的调用在 viewDidLoad 中,有时候返回 nil,有时候成功。
UICollectionView *cell = (UICollectionView*)[self.collectionView cellForItemAtIndexPath:indexPath];
简单的解决方法,是在调用之前添加
[self.collectionView layoutIfNeeded];
原因是,根据苹果开发者文档:
UICollectionView如果 cell 不是 visible 的 或者 indexPath 超过有效范围,就返回 nil。
在 iOS 10 上 还有一种解法:
[self.collectionVew setPrefetchingEnabled: NO];
但这种就牺牲了性能。
https://yiweifen.com/html/news/WaiYu/13536.html
2.点击cell reload oldIndex
[collectionView reloadItemsAtIndexPaths:@[oldIndexPath,indexPath]];
如果oldIndex和indexPath,会有显示bug
if (oldIndex != indexPath.row) {
[collectionView reloadItemsAtIndexPaths:@[oldIndexPath,indexPath]];
}
第19月第2天 cellForItemAtIndexPath 返回空的更多相关文章
- 《深入Java虚拟机学习笔记》- 第19章 方法的调用与返回
<深入Java虚拟机学习笔记>- 第19章 方法的调用与返回
- Handler 接收Parcelable ArrayList时返回空的错误
遇到一个问题,从handler 接收的Parcelable ArrayList返回空,调试发现这个arraylist生成的时候是有值的,传到handler就没值了 赋值的代码 new Thread(n ...
- 返回空的list集合*彻底删除删除集合*只是清空集合
---------- 要求返回空的List集合----------- List<String> allList = Collections.emptyList();// 返回空的List集 ...
- ubuntu下file_get_contents返回空字符串
ubuntu下file_get_contents返回空字符串 | 浏览:302 | 更新:2014-03-30 10:11 本文起初面临的问题是PHP中SoapClient不好使,最后file_get ...
- Effective Java 第三版——54. 返回空的数组或集合不要返回null
Tips 书中的源代码地址:https://github.com/jbloch/effective-java-3e-source-code 注意,书中的有些代码里方法是基于Java 9 API中的,所 ...
- shell脚本中sqlite3命令查询数据库失败返回空,并将错误信息打印到标准错误输出
shell脚本中sqlite3命令查询数据库失败返回空,并将错误信息打印到标准错误输出 如: #/bin/sh local ret='sqlite3 test.db "select test ...
- jenkins坑—— shell 命令返回空导致构建失败
今天用jenkins做CI遇到个坑,命令为:isSnapshot=`ls|grep isv-osp-service|grep -i snapshot` ls命令返回空的话,Jenkins构建就直接失败 ...
- python3中使用xpath无法定位,为什么一直返回空列表?
tbody问题: 在爬去某些网站一些信息的时候,xpath工具上显示类容是正确的,但是在scrapy代码中一直返回空列表 Scrapy的部分代码: class LotteryspiderSpider( ...
- laravel使用Dingo\Api通过response()->json()返回空对象
laravel使用Dingo\Api写接口跟android对接时,android一直反应解析错误,无法解析数据. { "status_code":200, "messag ...
随机推荐
- int ,Intege,String 三者之间的转换
注:如果使用JDK5.0的话,JVM会自动完成装包解包的. 1.Integer转换成int的方法 Integer i = new Integer(10); int k = i.intValue();即 ...
- Link-Cut Tree(LCT)&TopTree讲解
前言: Link-Cut Tree简称LCT是解决动态树问题的一种数据结构,可以说是我见过功能最强大的一种树上数据结构了.在此与大家分享一下LCT的学习笔记.提示:前置知识点需要树链剖分和splay. ...
- KEYENCE Programming Contest 2019 自闭记
A:签到. #include<iostream> #include<cstdio> #include<cstdlib> #include<cmath> ...
- Codeforces976D Degree Set 【构造】
题目大意:构造一个点数为dn+1的无向图,无向图中点的度数的集合等于给出的集合d. 题目分析: 当n=0的时候,一个点即可. 当n=1的时候,答案是一个包含d1+1个点的完全图. 否则将d2~dn-1 ...
- mysql test== 坑
错误 <if test="status == '1'"> 正确 <if test="status == '1'.toString()">
- 自定义git忽略规则
输入命令 >a.o git status 此时我想让git忽略这个文件的更新 输入命令 > .gitignore echo "a.o" >> .gitign ...
- 【BZOJ2484】[SDOI2011]打地鼠(暴力)
[BZOJ2484][SDOI2011]打地鼠(暴力) 题面 BZOJ 洛谷 题解 看到数据范围这题就应该是一个暴力题了. 先考虑假如我们知道了锤子的大小\(R*C\),那么显然只需要从左上角开始从左 ...
- Python进制表示及转换
进制表示: 二进制:>>> abin = 0b1000>>> abin8 八进制:>>> aoct = 0o123 (数字0,字母o)>&g ...
- Java -- JDBC 学习--PreparedStatement
可以通过调用 Connection 对象的 preparedStatement() 方法获取 PreparedStatement 对象.PreparedStatement 接口是 Statement ...
- A1027. Colors in Mars
People in Mars represent the colors in their computers in a similar way as the Earth people. That is ...