mirror of
https://github.com/Instagram/IGListKit
synced 2026-05-23 09:18:29 +00:00
fix crash on missing cell
Summary: If we apply the data updates outside the `performBatchUpdates`'s `updates` block, we need to make sure the layout is up to date. Otherwise, `performBatchUpdates` will try to do a layout before calling `updates` and get the wrong cells. Calling `[self.collectionView numberOfSections]` will update the section/item count, but won't get the cells. Reviewed By: Haud Differential Revision: D23604257 fbshipit-source-id: 02bbf0484c46cf6e7a12ed02d45ededb3b84ac19
This commit is contained in:
parent
a64f9b809d
commit
02ffb1163b
1 changed files with 5 additions and 2 deletions
|
|
@ -172,8 +172,11 @@ willPerformBatchUpdatesWithCollectionView:self.collectionView
|
|||
// `performBatchUpdates` right after.
|
||||
const BOOL skipPerformUpdateIfPossible = IGListExperimentEnabled(self.config.experiments, IGListExperimentSkipPerformUpdateIfPossible);
|
||||
if (skipPerformUpdateIfPossible) {
|
||||
// Force the `UICollectionView` data to sync before applying any new updates.
|
||||
[self.collectionView numberOfSections];
|
||||
// From Apple docs: If the collection view's layout is not up to date before you call performBatchUpdates, a reload may
|
||||
// occur. To avoid problems, you should update your data model inside the updates block or ensure the layout is
|
||||
// updated before you call performBatchUpdates(_:completion:).
|
||||
[self.collectionView layoutIfNeeded];
|
||||
|
||||
[self _applyDataUpdates];
|
||||
|
||||
if (!diffResult.hasChanges && !self.inUpdateItemCollector.hasChanges) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue