tags:

views:

68

answers:

2

I have a UIViewController that I want to display a second UIViewController as a dialog. Basically, the user presses a button in the first controller, then the second controller pops up and the user makes a selection.

When the user presses Save in the second controller, how does control get passed back to the parent controller, and how can I extract the user's choice from the second controller?

A: 

Consider looking into setting up a Modal View Controller under your root controller.

You could set up a property that stores the choice or selection. Its value would be accessible to the root controller through its instance of the modal view controller.

Alex Reynolds
A: 

It seems like there are two leading ways to do this:

  1. Create a custom delegate. Make the parent controller the delegate of the child controller. Have the child controller call an appropriate method in its delegate and simply use popNavigationController when you're done.

  2. Create a member variable in the parent controller referring to the child controller. When you display the child controller, store it in the member variable. Then override viewWillAppear: in the parent controller so that if the child controller reference is non-nil, it will interrogate the child for whatever information it needs. Then set the reference back to nil.

I personally like the second better. YMMV.

Bill