问题
I have an iOS application using coredata with three different models. The data is pulled from a json feed from a server then saved. Each API call is run on a thread using NSOperationQueue so they never execute at the same time. On the final call I save to the largest model being stored it is after the save happens that the application hangs. The UI becomes unresponsive and the debugger gives no errors. This only happens on the first load of the app, afterwards every subsequent load runs perfect. I have tried loading only the final api call and the error still happens. I receive the delegate callback controllerDidChangeContent: and do nothing in the method. I am stumped. Thank you folks for you assistance.
回答1:
It is "freezing" your app because you are most likely merging the save back to the main NSManagedObjectContext
via the NSManagedObjectContextDidChangeNotification
. This is known limitation prior to iOS 5.0.
Either you can update to 5.0 and use the parent child MOC design that was added or you can skip merging the contexts and -reset
the main context and force it to reload relevant data after the save.
来源:https://stackoverflow.com/questions/8171869/initial-coredata-save-freezes-app