断言失败 - [UITableView _endCellAnimationsWithContext:]尝试更新tableview时出现核心数据错误

时间:2013-04-26 12:40:21

标签: ios uitableview core-data nsfetchedresultscontroller

应用程序将照片上传到服务器。

当用户选择要上传的照片时,照片的信息会保存到核心数据中。填充了一个tableview,显示使用fetchedResultsController的照片列表。

tableview包含正在进行的上传,队列中的照片和已完成上传的部分,并根据状态进行相应更新。

但是现在当我尝试添加另一组照片进行上传时,再次选择,而上一组仍在上传时,我收到以下错误。

此后桌面视图显示为空白。我在桌面视图中看不到任何内容。

CoreData: error: Serious application error.  An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:.  Invalid update: invalid number of rows in section 1.  The number of rows contained in an existing section after the update (96) must be equal to the number of rows contained in that section before the update (62), plus or minus the number of rows inserted or deleted from that section (21 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out). with userInfo (null)

1 个答案:

答案 0 :(得分:1)

这里发生的事情是你第一次更新已插入21个单元格,并添加到模型中。表视图通过调用tableView:numberOfRowsInSection:来更新它的内部模型,它应该返回83(62 + 21),但是你的第二次更新已经为模型添加了一些项目,所以它实际上返回96.

这通常是因为您在主线程之外调用UIKit操作(非常糟糕),或者您在不更新同一函数中的tableview的情况下对模型进行了更改。