My app has an UITabViewController with 3 tabs. The first two tabs will read some data from disk and display it (done in viewDidLoad of the first two tabs).
The third tab has some kind of config information. If the user changes the config information in the third tab, i want the first two tabs to be refreshed, i.e., viewDidLoad should be re-called.
I cannot use viewWillAppear in the first two tabs, as the read from disk part is kind of intensive and I wouldn’t want to do it everytime the tab is clicked. Also, I need to do some auxiliary tasks (in addition to updating the first two tabs) when the third tab data is edited, so I want to reload the tabs via viewDidLoad, while doing those auxiliary tasks.
Use NSNotifications to do this.
Since the third tab is your config settings you will probability want to be storing these in
NSUserDefaultsso use theNSUserDefaultsDidChangeNotificationto watch for this in yourviewDidLoadmethod and move your reloadData code into its own method.Now this will trigger a call to the method
userDefaultsChanged:whenever your defaults are changed, add the method as follows.Edit: Alternative method to watch for specific default values