Attempt to dismiss from view controller while a presentation or dismiss is in progress

26,179

Solution 1

Added both iOS 6 and pre-iOS 6 answers:

iOS 5.0 and later

When you logout, add this check before dismissing:

if (![self.presentedViewController isBeingDismissed])
{
    [self dismissModalViewControllerAnimated:YES completion:nil];
}

iOS 4.X and less

Add this check before dismissing:

if (![[self modalViewController] isBeingDismissed])
{
    [self dismissModalViewControllerAnimated:YES];
}

Solution 2

Call these lines where you logout & then check:

if (![[self modalViewController] isBeingDismissed])
{
   [self dismissModalViewControllerAnimated:YES];
}

Solution 3

There are many things that may cause this, here are some options:

  1. You forgot to call super on one of the ViewController methods such as viewWillAppear, viewWillAppear etc. Consult the UIViewController documentation to see when you have to call super.
  2. The dismissModalViewControllerAnimated: method is being called more than once, this can happen if you added a target to the UIButton more than once.

To get better understanding of the problem please paste the code of both view controllers in its entirety.

Share:
26,179
Harish
Author by

Harish

Passionate iOS Mobile App Developer.

Updated on September 05, 2020

Comments

  • Harish
    Harish almost 4 years

    I have TWO UIViewController classes, where in FirstClass i have an UIButton for Login, when user taps on button, i will display SecondClass... For that i have done,

    SecondClass *index = [[SecondClass alloc] init];
    [self presentModalViewController:index animated:YES];
    

    In SecondClass i have a logout button, which will redirect to FirstClass, for that i have done,

    [self dismissModalViewControllerAnimated:YES];
    

    When i press Logout button in SecondClass, i get the warning msg

    **Attempt to dismiss from view controller <FirstClass: 0e39w88e160> while a presentation or dismiss is in progress!**
    

    What is the problem here..

  • Pavel Alexeev
    Pavel Alexeev almost 11 years
    presentedViewController and dismissViewControllerAnimated:completion: are available from iOS 5.0
  • Kevin Zych
    Kevin Zych almost 11 years
    Thanks @PavelAlexeev, I verified in the docs and updated my answer.