我正在使用UICollectionView的performBatchUpdates(_:completion:)
方法。問題是,有時我的複雜差異邏輯失敗,並返回不正確的部分插入。這會導致我插入的項目數量與數據源報告的數量不匹配。每當出現這種情況,我們得到以下錯誤:捕捉UICollectionView在Swift中執行批量更新斷言失敗?
Assertion failure in -[CollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:animator:]
Error when performing batch updates: Invalid update: invalid number of sections. The number of sections contained in the collection view after the update (25) must be equal to the number of sections contained in the collection view before the update (19), plus or minus the number of sections inserted or deleted (0 inserted, 0 deleted).
我認識到,正確的解決方法是修復我的版本比較邏輯,使得在項目的數量之間插入我打電話的數量沒有不匹配返回。
但是,我想要做的是讓即使我的邏輯在未來失敗,而不是衝突的應用程序,它只會重新加載收集視圖的數據。
我該如何在Swift中做到這一點?