5

Background - So in terms of approach at the high level there to me seems to be:

  1. Save/persist settings as you proceed through a chain of UINavigationController levels - so when initially starting to change settings, or create settings, there would need to a default set of values - i.e. so at any point of time if the application dies the settings would be valid
  2. save up changes as you go, and once you come back out of the UINavigationController tree of screens (with all settings set) there would be a point where you can save

This question is focusing on Option 2 which I was trying to implement.

The Plan - Whilst in a settings type UINavigationController I was going to pass existing (or default) details for one section of the settings from the parent view to the child view when the child view gets pushed onto the stack. The issue is when this data is updated, AND assuming I want to stick with the default Back Button, there does not seem to be a way to intercept the default Back Button, so that when I'm ready to pop the child off the stack just before this I will call a delegate which will pass the latest settings back to the parent.

QUESTION - How to pass updated data from a child controller back to the parent controller when using a UINavigationController and wanting to stick with the default Back Button (with the left arrow thing on it).

That is, probably I have isn't how to pass the data back I guess (I'm going to use a delegate), but rather how to hook into a callback method at the right point of time in the child controller so as to then use the delegate method to pass the data back.

Greg
  • 34,042
  • 79
  • 253
  • 454

2 Answers2

3

Using Delegate might be the solution for you.

Tutorial can be found:

http://timneill.net/2010/11/modal-view-controller-example-part-2/

which is very helpful for me.

Edit:

  1. Sounds like you need to make a back button yourself, info:

UINavigationController "back button" custom text?

and then add method:

[self.navigationController popViewControllerAnimated:YES]; 

to go back to the previous view. You can then add your own code to that back button.

  1. Even simpler solution: implement 'viewWillDisapper' method.

This gets called every time back button is pressed. But watch out if it goes to another view instead of going back.

Community
  • 1
  • 1
Xiao
  • 873
  • 6
  • 10
  • thanks Xiao - but in the child controller (if I'm on the right track) I'll still need a point where I'll actually call the delegate method to pass the data base - so I still need to determine how/when in the child controller can I call the delegate just after the Back Button is pressed no? – Greg Apr 05 '11 at 06:08
2

You may want to consider using a separate object as a SettingsController. You could set this as the delegate of the views or just call functions on it directly (most likely using a singleton design pattern). The settings controller could save the cached data, and when the wizard is finished (the last page is deallocated or something similar) you could have the settings controller save the data permanently.

Another option is to add a save or done button that would cause the save, otherwise the back button serves as a cancel button. From a UI point of view, if you don't have a "save" button the user would probably assume the settings are changed instantly.

drewag
  • 93,393
  • 28
  • 139
  • 128
  • good point re "if you don't have a "save" button the user would probably assume the settings are changed instantly" - even if I set up a delegate or separate object wouldn't I still need to hook into a point in the child controller just as the Back Button is pressed so that I can call the delegate/call the object? this is the part I'm a bit confused on. Perhaps the bottom line is if you want to stick with the default Back Button you need to save as changes are being made during the usage of the child controller, such that when the Back Button is pressed no further action is required? – Greg Apr 05 '11 at 06:12
  • marked as answer from the point of view of, given I want to use the back button, best to have the data updated on the spot as opposed to saved up and have to pass back - e.g. pass by reference the data structure to be updated ot the child controller – Greg Apr 05 '11 at 23:03