0

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!

lucgian84
  • 833
  • 4
  • 11
  • 29

2 Answers2

1

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];
}];
Arie Litovsky
  • 4,893
  • 2
  • 35
  • 40
0

Try with this....

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

Let me know if you have any problem.

user1673099
  • 3,293
  • 7
  • 26
  • 57