Strange warning dismissing modal view controller

21,062

Solution 1

Targeting iOS6, this is what worked for me:

if (![self.presentedViewController isBeingDismissed]) 
    [self.presentedViewController dismissViewControllerAnimated:YES
                                                     completion:nil];

Solution 2

I realise this is a late answer but maybe this will help someone else looking for a solution to this, here is what I did:

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

For me, i found that line of code was being called multiple times, I couldn't find out why so this was the easiest fix.

Solution 3

Thanks JDx for getting me on the right track. I adapted it to form this solution, which will remove the warning without using functions that are deprecated in iOS 6:

-(IBAction)backToMap
{
    if (![self.presentedViewController isBeingDismissed]) {
        [self dismissViewControllerAnimated:YES completion:^{}];
    }
}
Share:
21,062
Sparviero
Author by

Sparviero

Updated on July 05, 2022

Comments

  • Sparviero
    Sparviero almost 2 years

    I'm working on iOS 6. My application has a standard navigation controller with embedded a CustomViewController. In this controller I create a modal view like this:

    -(IBAction)presentModalList:(id)sender {
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
        StationsListViewController *list = [storyboard instantiateViewControllerWithIdentifier:@"StationsListViewController"];
        [list setStationsData: [self.stationsData allValues]];
        [self presentModalViewController:list animated:YES];
    }
    

    The modal controller show perfectly but dismissing generates a warning. The dismiss method in this controller is:

    -(IBAction)backToMap
    {
        [self dismissModalViewControllerAnimated:YES];
    }
    

    The warning generated is Warning:

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

    Any clues about that?

    Thanks

  • smileyborg
    smileyborg over 11 years
    I also ran into this problem. What may be happening is that your dimissModalViewControllerAnimated: call may be placed in a callback (IBAction) method that is (directly or indirectly) triggered by tapping the Cancel button on the modal view -- which already handles dismissing the modal view. So this dismissModalViewControllerAnimated: may be a duplicate and can be removed.
  • Olie
    Olie over 11 years
    I had a similar problem, but it was caused by a viewController being presented, then almost immediately dismissed (so dismiss was during present-animation.) So I had to check isBeingPresented.
  • huggie
    huggie about 11 years
    It's weird. I think @smileyborg is onto something. But I don't see why it's dismissing seemingly automatically? All I did was an unwind action, and I don't need to dismiss it directly?