0
votes

I am facing a problem in ios6 regarding dismissal of modalViewController

Here is code snippet I am sharing:

   UIViewController *controller=appdelegate.navigationController.topViewController;

   if(kDeviceVersion>=5.0){

     if(controller.parentViewController){

        if(controller.parentViewController.parentViewController){

            [controller.parentViewController.parentViewController dismissViewControllerAnimated:NO completion:nil];

        }

        [controller.parentViewController dismissViewControllerAnimated:NO completion:nil];

    }

}
else{

    if(controller.parentViewController){

        if(controller.parentViewController.parentViewController){

            [controller.parentViewController.parentViewController dismissModalViewControllerAnimated:NO];

        }

        [controller.parentViewController dismissModalViewControllerAnimated:NO];

    }

}

This code is working fine on ios4.0 to ios 5.1.1. But failed to work on ios6. Those modal view controller that I want to dismiss is not getting dismissed. Instead it showing this error.

attempt to dismiss modal view controller whose view does not currently appear. self = UINavigationController: 0xa947440 modalViewController = UINavigationController: 0x8c36170

But when I tried to present that view controller using presentModalViewController then it shows

Warning: Attempt to present on UINavigationController: 0xa947440 which is already presenting UINavigationController: 0x8c36170

Please suggest me what to do and how to fix this issue for ios6.

2
from which controller you display your modalView. Please specify its code. - NNikN

2 Answers

1
votes

Its not clear from your question which VC presents the VC you want to dismiss. However, I would recommend to always follow this rule:

Dismiss from the VC that also presented it. So for example if VC0 presents VC1 then also dismiss VC1 from within VC0. This is also actually the Apple recommended way as you can see from one of the answers to a very related question here opening and closing other UIViewControllers - any other approaches than to use protocol & delegate?

0
votes

Instead of using modal view controller I have used navigation controller and use push view using CAAnimation instead of present modal view controller

That is instead of this -----

    ShareViewController *share=[[ShareViewController alloc] initWithNibName:@"ShareViewController" bundle:nil];
    UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:share];
    share.modalPresentationStyle=UIModalPresentationFormSheet;
    share.modalTransitionStyle=UIModalTransitionStyleCrossDissolve;
    [self presentModalViewController:nav animated:YES];

    [share release];
    [nav release];

we can use this

    ShareViewController *share=[[ShareViewController alloc] initWithNibName:@"ShareViewController" bundle:nil];

    CATransition* transition = [CATransition animation];
    transition.duration = 0.4;
    transition.type = kCATransitionFade;
    transition.subtype = kCATransitionFromTop;

    [self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
    [self.navigationController pushViewController:share animated:NO];

    [share release];