views:

41

answers:

1

Hi I am using a navigation Controller on an iPhone app. I am able to pass data forward when I push a controller into the navigation stack but how do I pass data back when I pop the controller.

What I am basically trying to achieve is the root navigation controller view displays a number of fields that can be edited. A user then clicks on one of the fields to be edited and a EditViewController is pushed onto the stack with the name of the field the user wants to edit. Now the users enters the new value of the field and presses save to pop the view controller. So how do I get the value from the editViewController back to the root navigation controller view?

A: 

There's a couple of approaches:

  • When pushing your EditViewController, pass it a pointer to the value to be modified, not the value itself. That way, the controller can modify the value through the pointer before it is popped.
  • Implement a delegation, where your root view controller implements an EditViewControllerDelegate protocol. If it then passes itself as a parameter to the EditViewController, the EditViewController can call appropriate delegate methods to inform the root view controller of any changes.

The first is simplest, the second the more flexible.

Mac
The delegation sounds interesting. I will try to implement that. Thanks
Garfield81