Instagram / Instagram/IGListKit

[AppleBug] UICollectionView reload displaced section crashes in batch update

Open
#690 4 comments 0 reactions 0 assignees View on GitHub
radar
Dominant language
Objective-C
Stars
13.1k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

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:
- Section 2 moves to section 4
- Section 3 is reloaded
- Section 4 is deleted
- A new section is inserted into section 2

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](https://github.com/Instagram/IGListKit/files/949775/UICollectionViewReloadDisplacement.zip)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.