I have a managed object context in a separate thread that is creating a few hundred managed objects, and when it saves, the did save notification is passed to the main thread and my other context (on the main thread) is updated:
In Thread
[ApplicationDelegate performSelectorOnMainThread:@selector(managedObjectContextDidSave:)
withObject:notification
开发者_JAVA技巧 waitUntilDone:NO];
The problem is that the merging is taking a very long time, sometimes 40-50 seconds, and this is locking up the main thread & UI. Is there any reason why it would take this long to update?
Edit
This appears to only happen if there is a fetched results controller that is currently displaying data that will be affected by the merging. Any ideas?
I am assuming that your NSFetchedResultsController
has a NSFetchedResultsControllerDelegate
which is having to handle lots of updates as a result of the merge. These updates will result in lots of activity within the table, which might be causing the lag.
What you might have to do is create a wrapper method which when called on the main thread temporarily removes the delegate from the NSFetchedResultsController
, then invokes managedObjectContextDidSave
, then refreshed the table, then reinstates the NSFetchedResultsControllerDelegate
.
精彩评论