0

我有一个可以向MutableProperty<[Stuff]>

但是当我重新加载collectionViewwith 时collectionView.reloadData()。Web 套接字向 中添加或删除数据MutableProperty<[Stuff]>,因此会崩溃

由于多种原因,这里有一些错误:

  • 当 collectionView 方法使用我的列表时索引超出范围
  • 无效的项目数会导致崩溃,例如:Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of sections. The number of sections contained in the collection view after the update (58) must be equal to the number of sections contained in the collection view before the update (59), plus or minus the number of sections inserted or deleted (0 inserted, 0 deleted).'

任何人都有一个好的建议或最佳实践来做到这一点?我已经看到 MutableProperty 是线程安全的

我知道它为什么会崩溃。它崩溃是因为 websockets 在 期间添加或删除数组中的值reloadDatacollectionView但我不知道如何解决它。我知道我们可以使用信号量,但我正在寻找优雅的东西

4

1 回答 1

0

您应该向我们展示更多您的代码,以便我们更好地理解。但是,如果您在 delegates :numberOfSections和中返回一个固定值numberOfRowsInSection,则需要在调用之前更新它们,collectionView.reloadData()以便这两个委托返回每个部分中的确切数量的部分和项目。

于 2018-10-29T11:20:46.140 回答