I'm having serious troubles with the animation of a UICollectionView, similar to the problem mentioned here: UICollectionView crashes when rearranging items between sections
Let's say I have a UICollectionView with 5 different sections, each with 10 cells. I would like to update the CollectionView with an animation, so the cells will be reordered into 10 sections. No cells with new content will be added nor existing cells removed.
Therefore I'm performing a batch update:
[_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;
}];
If I perform insertSections, deleteSections, insertItemsAtIndexPath, deleteItemsAtIndexPath and reloadData once the block was performed everything works fine which means my dataSource and delegates work properly in theory. Except it's not animated yet ...
If I perform insertSections, deleteSections and moveItemAtIndexPath (which should work since the cells only get rearranged) i get this little bug: cannot move a row into a newly inserted section (5)
If I perform insertSections, deleteSections and moveItemAtIndexPath but exclude any movement into a newly inserted section I obviously get invalid number of items in the sections.
Does anybody have a solution for this problem?
I followed john1034's link and figured out a quite tricky way to do it. You have to split up the work in three steps:
For sure there are many lines which can be further improved. Especially the search functions are quite inefficient...