加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xcode – UICollectionView reloadItemsAtIndexPaths

发布时间:2020-12-14 18:03:48 所属栏目:百科 来源:网络整理
导读:我一直试图绕过UICollectionView的reloadItemsAtIndexPaths方法. 我有一个名为objectsArray的对象数组.当用户滚动到我的集合视图的底部时,我从后端获取下一批对象,并通过调用[objectsArray addObjectsFromArray:objects]将其附加到objectsArray;这样做后,我
我一直试图绕过UICollectionView的reloadItemsAtIndexPaths方法.

我有一个名为objectsArray的对象数组.当用户滚动到我的集合视图的底部时,我从后端获取下一批对象,并通过调用[objectsArray addObjectsFromArray:objects]将其附加到objectsArray;这样做后,我调用[self.collectionView reloadData],我知道这是昂贵的.

我想用下面的代码进行优化,但是在调用reloadItemsAtIndexPaths时我得到一个断言失败.

if (self.searchPage == 0) {
        parSEObjectsArray = [[NSMutableArray alloc] initWithArray:relevantDeals];
        [self.collectionView reloadData];

    } else {

        NSMutableArray *indexPaths = [[NSMutableArray alloc] init];
        for (int i = 0; i < [relevantDeals count]; i++) {
            NSIndexPath *indexPath = [NSIndexPath indexPathForItem:i inSection:0];
            [indexPaths addObject:indexPath];
        }

        [parSEObjectsArray addObjectsFromArray:relevantDeals];
        [self.collectionView reloadItemsAtIndexPaths:indexPaths];
        //[self.collectionView reloadData];
    }

错误:
*断言失败 – [UICollectionView _endItemAnimations],/ SourceCache / UIKit / UIKit-2903.2 / UICollectionView.m:3716

非常感谢任何帮助/提示.

谢谢!

解决方法

看起来添加的项目是新的,换句话说,您正在添加以前不存在的项目.在这种情况下,只需用insertItemsAtIndexPaths替换reloadItemsAtIndexPaths:indexPaths:

[self.collectionView insertItemsAtIndexPaths:indexPaths]; // Use this for newly added rows
//[self.collectionView reloadItemsAtIndexPaths:indexPaths]; // Use this for existing rows which have changed

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读