views:

107

answers:

1

I have an application with several UITableViewControllers. Now, the user is allowed to change "Data source". In that case I need to invalidate (reset) data in the relevant UITableViews.

I figured out, that I can use NSNotificationCenter and add these controllers as observers to events which will be generated when the data source changes.

The question is, how do I reset the underlying tables? I can, of course, set some boolean flag, and call UITableView:reloadData in viewWillAppear or viewDidAppear, but I was wondering, if there's a cleaner way of doing it.

Or perhaps I'm completely missing the point, and I don't need NSNotificationCenter altogether. Thank you very much in advance.

A: 

The question is, how do I reset the underlying tables? I can, of course, set some boolean flag

I'm not sure why you need to use a flag here. When your view controller gets the notification, have it reload the table in the notification handler.

Updating your table will work a bit differently if your UITableView is attached to an NSFetchedResultsController. Is it?

Shaggy Frog
While this is one possibility, I ruled it out, as the data loading is an expensive operation, which I only want to perform on demand, i.e. when the user enters this view. Having multiple tables reload their data just because the user changed the data source is too costly. The user might not visit that view at all.
Roman
Then reload in viewWillAppear.
Shaggy Frog
Based on a flag, like I originally suggested? :(
Roman