简体   繁体   中英

Dismissing previously presented modal view controller before currently visible one

I have 2 UIViewController's presented with [self presentViewController:viewController animated:YES completion:nil]; , I want to dismiss the first one of them, without animation (It's not visible to the user anyway) and when the second one (currently visible) will be dismissed, the user will see the parent view controller who present them both.

- Parent
  - First -> Dismiss first without animation
    - Second -> Dismiss second with animation

How can I do that?

With your current view controller hierarchy if first view controller will be dismissed it will dismiss second view controller automatically. If you don't want that behaviour than make parent present second view controller. You can do that from first view controller by using [self.presentingViewController presentViewController:secondViewController animated:YES completion:nil]

Why do you want to do this?

You should do it like this for cleaner view hierarchy and better user experience:

Present first view controller :

[self presentViewController:viewController1 animated:YES completion:nil];

Dismiss first & present second view controller :

__weak MyViewController *aBlockSelf = self;

[self dismissViewControllerAnimated:YES completion:^{
    [aBlockSelf presentViewController:viewController2 animated:YES completion:nil];
}];

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