Instagram / IGListKit

A data-driven UICollectionView framework for building fast and flexible lists.
https://instagram.github.io/IGListKit/
MIT License
12.83k stars 1.54k forks source link

[AppleBug] UICollectionView reload displaced section crashes in batch update #690

Open rnystrom opened 7 years ago

rnystrom commented 7 years ago

Summary: When reloading a section that is displaced/shifted inside -[UICollectionView performBatchUpdates:completion:], it is possible to hit an NSInternalInconsistencyException stating "attempt to perform an insert and a move to the same section (i)" when the sections used in insertSections:, deleteSections:, reloadSections: , and moveSection:toSection: do not intersect.

For instance, a collection view who's data source is updated to reflect the following section mutations will crash:

[self.collectionView performBatchUpdates:^{
  [self.collectionView moveSection:2 toSection:4];
  [self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:3]];
  [self.collectionView deleteSections:[NSIndexSet indexSetWithIndex:4]];
  [self.collectionView insertSections:[NSIndexSet indexSetWithIndex:2]];
} completion:nil];

Steps to Reproduce:

  1. Open attached UICollectionViewReloadDisplacement sample app
  2. Hit "Play" bar button
  3. Crash

Expected Results:

Actual Results: Crash with exception:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to perform an insert and a move to the same section (4)'

Version: iOS 9.3.4, 8.4, and 10.0 beta 4

Configuration: iPhone 6, iPhone 6s simulator

UICollectionViewReloadDisplacement.zip

rnystrom commented 7 years ago

Please dupe

https://openradar.appspot.com/radar?id=5037608161771520

PeterAntonsen commented 6 years ago

I think there's something about, deletes and reloads using the index'es of the old-dataset, whereas inserts, uses the index'es of the new-dataset.. so you might want to check up on your relevant indexes as I think this is your issue..

rnystrom commented 6 years ago

@PeterAntonsen this is actually a confirmed issue with UICollectionView

Sent with GitHawk

PeterAntonsen commented 6 years ago

@rnystrom, fair enough, just stumbled across this, weighing in from memory as it reminded of another thread I saw.. hope it gets solved :)