Best way to reuse 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 get this dynamic list from a SQLite database and I would have the same underlying problem.

The problem is, since the list of items for my table view in the DocumentListController will change based on the user's selected selection, I need to load my list after the table view is displayed.

I am currently using -viewWillAppear:

to trigger this "update" of items from my web service. I was wondering if this is the best way to make this update, or if I will be looking into using a different method. I tried using -viewDidLoad

but this method is only called once for the DocumentListController and I have to check on each call if the "selection" has changed and if so I need to call my webservice again.

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


source to share

1 answer

Since you are fetching data over the network, I suggest posting a notification after it has been processed. Your DocumentListController should register for this notification and call its reviewData table in your notification handler.

Another approach, if the data will always show when the view is rendered, is what you suggested - update the table in viewWillAppear.



All Articles