开发者

Consistent update UITableview after Coredata updates

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:

  1. 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.

  2. Register for the NSManagedObjectContextObjectsDidChangeNotification. In your notification method, handle the cases NSInsertedObjectsKey, NSUpdatedObjectsKey, and NSDeletedObjectsKey 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜