tags:

views:

335

answers:

3

What I'm trying to do:

  1. Display a modal view, where I get some user input
  2. Display another one and get more input
  3. Do some stuff with the input from 1. and 2.

Problem is: presentModalViewController:animated: is non blocking. That means I can't just do the steps 1.-3. sequentially.

How I tried to solve it:

ViewController0 builds ViewController1 and gives him a reference to itself, then does presentModalViewController:animated:. ViewController1 will gather user input, then call a method on ViewController0 (it has the reference). That method will build ViewController2 and do the same as with the first one. ViewController2 will also call a method on ViewController0 (might even be the same one). Now ViewController0 has all the data (or should) and can proceed to step 3.

Problem with this approach:

  1. It looks like a horrible hack (there has to be a better way to do it).
  2. It doesn't work. :-) The problem is when ViewController0 tries to display ViewController2. That one won't even get displayed. My assumption (I'm new to iPhone programming, but I did some Windows programming before) is that this operation is not done instantly, but posted somewhere for further processing (similar to the WIN32 msg queue), and so it will somehow conflict with the operation of removing ViewController1!

So, any idea how I can either solve this problem in a simpler way or make it work this way?

A: 

You might want to make it a single modal view controller than contains 2 sub-controllers. The main modal view controller can be a UINavigationController so that the second sub-controller gets pushed to the navigation stack, or you could make it a plain view controller and just swap the sub-controllers' views programattically.

The way you tried to do it should work, though might feel a bit clunky. Make sure you're dismissing the first modal view controller before you present the second one.

Daniel Dickison
I'd like the logic of displaying the two modals to stay in the main view, since I don't always want to display both. Sometimes only the first, sometimes only the second. Therefore I don't really like your solution. But it is an option.
ionut bizau
+1  A: 

Have you tried calling [self presentModalViewController:ViewController2] from ViewController1?

I ask because I know the approach works, having initiated a modal view controller from a VC0 with:

[self.navigationController presentModalViewController:VC1]

And then at one point in VC1 doing as I described above. The second modal view comes up as an overlay, when dismissed you return to VC1.

Kendall Helmstetter Gelner
Your reply was good, but I still needed to dismiss VC1 thus returning to VC0. I got pretty confused until I found the solution I mentioned, which is to dismiss VC1 directly - in that case VC2 is automatically dismissed.
ionut bizau
A: 

I found the solution to this problem here: http://forums.macrumors.com/showthread.php?t=513131 (lawicko's answer).

Thanks for your replies anyway.

ionut bizau
One note to the above answer - to dismiss VC1 in order to return to VC0, you can't do that from VC2! You need to call VC1, which needs to dismiss itself...
ionut bizau