3

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?

Arun_
  • 1,806
  • 2
  • 20
  • 40
  • Well, from the way your error says, it seems that you are trying pop from the view controller at the same time that the view is modally transitioning.. – user2277872 Sep 21 '13 at 15:32
  • Maybe you can present the modal view right from the `navigationViewController`. – Kyle Fang Sep 21 '13 at 15:33
  • Or, if you are okay with it. `popToRoot` at the dismiss completion block. – Kyle Fang Sep 21 '13 at 15:34
  • i can't use popToRootViewController as the current view is presentmodalviewcontroller,so i guess i have to do like dismissPresentmodalviewcontroller -> popToRootViewController.@kyle – Arun_ Sep 21 '13 at 15:43
  • i have edited the code,still it's not working @kyle – Arun_ Sep 21 '13 at 15:49

1 Answers1

7
[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.

Kyle Fang
  • 1,139
  • 6
  • 14