zoukankan      html  css  js  c++  java
  • 第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 setPrefetching​Enabled: 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]];

     

    }

  • 相关阅读:
    用到的一些方法
    Android屏蔽Home键
    Android自定义GridView显示一行,并且可以左右滑动
    模糊匹配字母大小写
    Android四大组件之Content Provider的学习
    用于小数据存储的SharedPreferences
    Android小知识点
    【译】用C/C++操作链表
    和好友的QQ记录,多关注哈需要关怀的人
    岁不待人_20080321
  • 原文地址:https://www.cnblogs.com/javastart/p/8689945.html
Copyright © 2011-2022 走看看