Dismissing 2 ViewController consecutively

ios, viewcontroller

Solution

This is now an old question, but it seems to be exactly the problem I am having presently. Here what I did:

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

And it works for me. I hope it can be useful to someone.

Problem

I try 2 ways to dismissed 2 viewcontrollers consecutively but only one of them got dismissed not the second one method1 ``` -(void) LoginDone:(NSNotification *)notif { [self dismissViewControllerAnimated:YES completion:NULL]; //previous viewcontroller [self dismissViewControllerAnimated:YES completion:NULL]; //current viewcontroller } ``` method2 ``` -(void) LoginDone:(NSNotification *)notif { [self dismissViewControllerAnimated:YES completion:NULL]; [[NSNotificationCenter defaultCenter] postNotificationName:@"LoginDone2" object:nil]; } -(void) LoginDone2:(NSNotification *)notif { [self dismissViewControllerAnimated:YES completion:NULL]; } ``` I need to find out a way to dismiss both the previous viewcontroller and current viewcontroller consecutively.

Original source