我有2个托管对象上下文:(1)创建为NSMainQueueConcurrencyTypeUI /主线程使用,(2)创建为NSPrivateQueueConcurrencyType网络使用.这两个上下文都转到持久性存储(即,我没有使用父/子上下文).
对于视图控制器,我使用UITableViewController的NSFetchedResultsController是使用第一个UI管理对象上下文的.
我正在通过观察将第二个托管对象上下文中的更改合并到第一个上下文中NSManagedObjectContextDidSaveNotification.
该应用程序正常工作,直到它处理网络响应,导致插入新对象和在第二个上下文中删除现有对象.保存第二个上下文后,将NSManagedObjectContextDidSaveNotification触发和更改合并到第一个上下文中.NSFetchedResultsController调用委托方法并将新行添加到表中,但不删除表示已删除对象的行.
如果我在表视图上尝试其他操作,比如重新加载表或更新其他对象,我会在控制台日志中获得此断言:
*** Assertion failure in -[UITableView _endCellAnimationsWithContext:],
/SourceCache/UIKit/UIKit-2380.17/UITableView.m:1070
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 0. The number of rows contained in an existing section after the
update (6) must be equal to the number of …Run Code Online (Sandbox Code Playgroud)