10
votes

I have a navigation controller which present one modal viewController. From inside this modal viewController I present another modal viewController. All I want is to get back from the last modal viewController to the navigationController (the root viewController).Something similar with popToRootViewController, but adapted for modalViewControllers;

NavigationController -> present Modal ViewController A -> present Modal ViewController B

From modal ViewCOntroller B I want to return to navigationCOntroller.

Is this possible?

Appreciate, Alex.

2
More generic way to dismiss more that one modal view controllers is hereRamis

2 Answers

31
votes

In iOS 5 you need to do

[self.presentingViewController.presentingViewController dismissModalViewControllerAnimated:YES]

Edit: As of iOS 6 dismissModalViewControllerAnimated: is deprecated.

You need to call

[self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:^{ // Do something on completion}]

5
votes

Problem solved :)

I tried

[self.parentViewController.parentViewController dismissModalViewControllerAnimated:YES];    

and works.

Thanks.