I have an application that uses coredata. The Download of data happens in a class A. Coredata updates/saves/deletes are in the SharedDelegate (B). The delegate initiates the download in A and implements its protocol to get notified when a download was completed, so the delegate can update its data in the database.
Now, after that happened, I would like t开发者_StackOverflowhe class C, that has the UITableview, to update its rows and cells so I can show the new content.
How would I correctly notifly C, that it can update its table? What are the possible errors that can occur?
The download and update happens asynchronously of course and so far, I update only after ALL downloads have been completed.... I would like to split the task, so to say.
Any hints?
Two options:
Use an
NSFetchedResultsController
as the table view's data source. The documentation forNSFetchedResultsController
contains a lot of code that you can copy & paste into your app to manage table view updates whenever the managed object context changes.Register for the
NSManagedObjectContextObjectsDidChangeNotification
. In your notification method, handle the casesNSInsertedObjectsKey
,NSUpdatedObjectsKey
, andNSDeletedObjectsKey
and update your table view accordingly.
Use NSNotificationCenter
. Set the class C to listen for notifications and reload the data accordingly. When the SharedDelegate B updates the data, post a notification.
精彩评论