views:

51

answers:

1

My application presents a modal view (A) from the main view that lets the user make a selection. When they make that selection it opens a second modal view (B) on top of the first one (A).

When I'm done with the second modal view (B), and want to dismiss it, I would like to dismiss the first one (A) and the second one (B) at the same time as I no longer need the user to return to that one (A) either.

The only thing I came up with is:

[self.parentViewController.parentViewController.parentViewController. dismissModalViewControllerAnimated:YES];

It works, but it just doesn't look correct. Is this OK to do or is there a more accepted way to do this?

+1  A: 

I don't think that your way is wrong. It is what Apple documentation recommends:

If you present several modal view controllers in succession, and thus build a stack of modal view controllers, calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. When this happens, only the top-most view is dismissed in an animated fashion; any intermediate view controllers are simply removed from the stack. The top-most view is dismissed using its modal transition style, which may differ from the styles used by other view controllers lower in the stack.

vodkhang
OK, thank you. It just looked strange to string so many parentViewController statements together to make it work.
John