mergeChangesFromContextDidSaveNotification Briefly Displays Both Contexts In NSTableView
I have a managedObjectContext for the main application that has a bound NSArrayController and NSTableView displaying the contents of the NSArrayController.
Periodically I use a background thread with a second managedObjectContext that goes and retrieves the latest data from a web server. Once the data has been returned and parsed on the background thread, it is merged with the main context after a mergeChangesFromContextDidSaveNotification.
Immediately after the notification fires (and I assume during the merge), the table shows duplicate entries of every item (which would be accurate if the two contexts were showing both their data at the same time). After a couple of seconds the table correctly displays the data and the duplicates are removed.
I presume the NSArrayController is observing the context as it is going through the merg开发者_开发问答e and allowing the table to show the pre- and post- merge files.
Is there an acceptable method to stop the array controller from updating itself until the merge is complete?
I could do this outside of IB bindings and forcibly update the array controller, but I'm pretty sure that I must be doing something slightly wrong in either my bindings or during the process of the merge.
Any help or suggestions much appreciated.
You are most likely not sending a beginUpdate to the tableview before merging the two context so the tableview ends up trying to display the logical table in its in-between state. Freeze the tableview upon receiving the notification and then unfreeze it when the context have been merged.
加载中,请稍侯......
精彩评论