Best way to re-use a UITableView with dynamic data?

My application has a series of table views based on some hierarchical data. For example, the user selects "Browse by XYZ" on my CategoryListController, and then I load my DocumentListController based on that selection.

Right now I'm getting the list through a web service that returns some JSON data, but that's beside the point. I could retrieve this dynamic list from a SQLite database, and I would have the same underlying challenge.

The problem here is that since the list of items for my table view in DocumentListController will change depending on which selection the user tapped on, I have to load my list after the table view is displayed.

Right now I'm using -viewWillAppear: to trigger this "refresh" of the data items from my web service. I was wondering if this is the best way to be doing this refresh, or if I should look into using a different method. I tried using -viewDidLoad but that method gets called only once for the DocumentListController, and I have to check at every invocation if the "selection" has changed, and if so, I need to call my web service again.

What's the best way to do something like this?

Answers


Since you retrieve the data through the network, I would suggest to post a notification after you process it. Your DocumentListController should register for that notification and invoke its table view's reloadData in the notification handler.

Another approach, if the data will always be there when displaying the view, is what you've suggested - update table view in viewWillAppear.


Need Your Help