Reputation: 1055
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 the 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?
Upvotes: 2
Views: 1269
Reputation: 73936
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.
Upvotes: 1
Reputation: 135548
Two options:
Use an NSFetchedResultsController
as the table view's data source. The documentation for NSFetchedResultsController
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 cases NSInsertedObjectsKey
, NSUpdatedObjectsKey
, and NSDeletedObjectsKey
and update your table view accordingly.
Upvotes: 6