简体   繁体   中英

Pop to the main view controller

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!

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];
}];

Try with this....

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

Let me know if you have any problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM