一旦我有了我的数据,我想做以下:
[self.collectionVIEw performBatchUpdates:^{ for (UIImage *image in images) { [self.collectionVIEw insertItemsAtIndexPaths:****] }} completion:nil];
现在代替***,我应该传递一个NSIndexPath数组,它应该指向要插入的新项目的位置。提供位置后,我很困惑,我该如何提供应该在该位置显示的实际图像?
谢谢
更新:
在从newImages的数据添加新数据之前,resultsSize包含数据源数组self.results的大小。
[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];解决方法 参见 Inserting,Deleting,and Moving Sections and Items从“ Collection View Programming Guide for iOS”:
To insert,delete,or move a single section or item,you must follow
Update the data in your data source object. Call the appropriate method of the collection vIEw to insert or delete the section or item.
these steps:It is critical that you update your data source before notifying the
collection vIEw of any changes. The collection vIEw methods assume
that your data source contains the currently correct data. If it does
not,the collection vIEw might receive the wrong set of items from
your data source or ask for items that are not there and crash your
app.
所以在你的情况下,您必须首先将图像添加到集合视图数据源,然后调用insertItemsAtIndexPaths。然后,收集视图将要求数据源代理功能为插入的项目提供视图。
总结以上是内存溢出为你收集整理的objective-c – UICollectionView使用performBatchUpdates执行更新全部内容,希望文章能够帮你解决objective-c – UICollectionView使用performBatchUpdates执行更新所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)