Question

In my app I've 2 view controller that they appears by using a modal transition, now I developed the 3rd view controller and I put a button to go back to the main view controller, but how I can go back to the main view controller? I tried with this:

[self dismissViewControllerAnimated:YES completion:nil];

but with this code I go back to the 2nd view controller. How I fix it?

Thank you!

Was it helpful?

Solution

Assuming your first modal presented the second modal, the following should work:

__weak UIViewController *vcThatPresentedCurrent = self.presentingViewController;

[self dismissViewControllerAnimated:YES completion:^{

    [vcThatPresentedCurrent dismissViewControllerAnimated:YES completion:nil];
}];

OTHER TIPS

Try with this....

[self.presentingViewController.presentingViewController
 dismissViewControllerAnimated:YES completion:nil];

Let me know if you have any problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top