【发布时间】:2015-11-12 22:58:03
【问题描述】:
我在 UICollectionView 的动画上遇到了严重的问题,类似于这里提到的问题:UICollectionView crashes when rearranging items between sections
假设我有一个包含 5 个不同部分的 UICollectionView,每个部分有 10 个单元格。 我想用动画更新 CollectionView,因此单元格将重新排序为 10 个部分。不会添加包含新内容的单元格,也不会删除现有单元格。
因此我正在执行批量更新:
[_resultCollectionView performBatchUpdates:^{
[_resultCollectionView insertSections:insertSections];
[_resultCollectionView deleteSections:deleteSections];
//[_resultCollectionView insertItemsAtIndexPaths:insertIndexPaths];
//[_resultCollectionView deleteItemsAtIndexPaths:deleteIndexPaths];
for (all items which need to be moved...) {
[_resultCollectionView moveItemAtIndexPath:sourcePath toIndexPath:destinationPath];
}
} completion:^(BOOL finished) {
//[_resultCollectionView reloadData];
nil;
}];
如果我在执行块后执行 insertSections、deleteSections、insertItemsAtIndexPath、deleteItemsAtIndexPath 和 reloadData,一切正常,这意味着我的数据源和委托在理论上可以正常工作。除了它还没有动画...
如果我执行 insertSections、deleteSections 和 moveItemAtIndexPath(这应该可以工作,因为单元格只会重新排列)我会遇到这个小错误: 无法将行移动到新插入的部分 (5)
如果我执行 insertSections、deleteSections 和 moveItemAtIndexPath 但将任何移动排除在新插入的部分中,我显然会在这些部分中获得无效的项目数。
有人有解决这个问题的方法吗?
【问题讨论】:
-
你检查过这个问题吗?我觉得@sponessuck 的答案可以解决您的问题。 stackoverflow.com/questions/26299502/…
标签: ios objective-c uicollectionview