我有一个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)