我正在使用UICollectionView的
然而,我的目标是,即使我的逻辑在未来失败,也不会使应用崩溃,而是重新加载集合视图的数据。
performBatchUpdates(_:completion:)
方法。问题在于,有时我的复杂差异逻辑会失败并返回一个不正确的插入节的数量。这导致我插入的项目数与数据源报告的数量不匹配。每当发生这种情况时,我们会收到以下错误:
我意识到正确的解决方案是修复我的差异逻辑,使返回的项目数与我调用的插入数不相冲突。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中实现这个?