Warning: Attempt to dismiss from view controller <UINavigationController: 0xb359a20> while a presentation or dismiss is in progress

Arun_ picture Arun_ · Sep 21, 2013 · Viewed 9.5k times · Source

In my Application what i'm doing is:

rootViewController -> pushViewController -> pushViewController -> pushViewController -> presentModalViewController

From presentModalViewController i want to go to rootViewController Directly.

So what i did is :

while(theViewController = [theObjectEnumerator nextObject ])
     {
         if([theViewController modalTransitionStyle] == UIModalTransitionStyleCoverVertical)
         {
             [self.mNavigationController popToRootViewControllerAnimated:
              YES];
         }
     }
 }else
while(theViewController = [theObjectEnumerator nextObject ])
{
    if([theViewController modalTransitionStyle] == UIModalTransitionStyleCoverVertical)
    {
        [self.mNavigationController dismissModalViewControllerAnimated:YES];
    }
}

but here i'm getting a message
Warning: Attempt to dismiss from view controller while a presentation or dismiss is in progress!

and after this app crashes.

I searched about this but couldn't find anything useful for me, Can any body explain why this is happening?

Answer

Kyle Fang picture Kyle Fang · Sep 21, 2013
[self dismissViewControllerAnimated:YES completion:^{
    [(UINavigationController *)self.presentingViewController popToRootViewControllerAnimated:YES];
}];

This code work fine for me,

Important:

the viewController must be presented by the navigationController. (In most cases) If not, call self.presentingViewController.navigationController.