相关疑难解决方法(0)

UICollectionView使用performBatchUpdates执行更新

我有一个UICollectionView我试图动态/动画插入项目.所以我有一些函数可以异步下载图像,并希望批量插入项目.

获得数据后,我想执行以下操作:

[self.collectionView performBatchUpdates:^{
    for (UIImage *image in images) {
        [self.collectionView insertItemsAtIndexPaths:****]
    }
} completion:nil];
Run Code Online (Sandbox Code Playgroud)

现在代替了***,我应该传递一个数组NSIndexPaths,它应该指向要插入的新项目的位置.我提供位置后非常困惑,如何提供应该在该位置显示的实际图像?

谢谢


更新:

resultsSize包含数据源数组的大小self.results,在从数据中添加新数据之前newImages.

[self.collectionView performBatchUpdates:^{

    int resultsSize = [self.results count];
    [self.results addObjectsFromArray:newImages];
    NSMutableArray *arrayWithIndexPaths = [NSMutableArray array];

    for (int i = resultsSize; i < resultsSize + newImages.count; i++)
          [arrayWithIndexPaths addObject:[NSIndexPath indexPathForRow:i inSection:0]];

          [self.collectionView insertItemsAtIndexPaths:arrayWithIndexPaths];

} completion:nil];
Run Code Online (Sandbox Code Playgroud)

xcode objective-c ipad ios uicollectionview

31
推荐指数
3
解决办法
7万
查看次数

标签 统计

ios ×1

ipad ×1

objective-c ×1

uicollectionview ×1

xcode ×1