I’ve got a Utility Application for iPhone 3.1.3. I have my main view loading fine. I flip over to the flipside view of the utility app and change some settings. How can I call the code I’ve currently got in viewDidLoad in the main view to refresh it, as settings have changed?
Do I create a public method and call it from the viewDidUnload method of the flipside view? Do I call viewDidLoad directly? What’s the best way to do this?
Firstly, you should never call
viewDidLoaddirectly. It probably won’t cause any problems, but it’s best to leave a method like that to be called by the underlying API only. Just move out some of the view initialization into a new method likeconfigureViewForSettingsor something along those lines.The best approach would be to use delegation. This is most suitable when you need to send back some sort of data or notification to a ‘parent’ view. Create a new protocol
MySettingsViewDelegatewith a method likesettingsViewChangedSettings:(MySettingsView *)settingsView. Then on your settings view controller add aid<MySettingsViewDelegate> delegateproperty.When the settings change call the delegate method like this:
And in your main view controller, when you create/display the settings view, set yourself to be the delegate
Then somewhere: