简体   繁体   English

ios6中解雇modalViewcontroller错误

[英]dismissal modalViewcontroller error in ios6

I am facing a problem in ios6 regarding dismissal of modalViewController 我在ios6中遇到有关解雇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. 这段代码在ios4.0到ios 5.1.1上正常工作。 But failed to work on ios6. 但是无法在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 自我= UINavigationController:0xa947440 modalViewController = UINavigationController:0x8c36170

But when I tried to present that view controller using presentModalViewController then it shows 但是,当我尝试使用presentModalViewController呈现该视图控制器时,它将显示

Warning: Attempt to present on UINavigationController: 0xa947440 which is already presenting UINavigationController: 0x8c36170 警告:尝试在已经呈现UINavigationController:0x8c36170的UINavigationController:0xa947440上呈现

Please suggest me what to do and how to fix this issue for ios6. 请建议我该怎么做以及如何解决此问题的ios6。

Its not clear from your question which VC presents the VC you want to dismiss. 从您的问题尚不清楚,哪个VC提供了您要关闭的VC。 However, I would recommend to always follow this rule: 但是,我建议始终遵循以下规则:

Dismiss from the VC that also presented it. 从也提出它的VC撤消。 So for example if VC0 presents VC1 then also dismiss VC1 from within VC0. 因此,例如,如果VC0提供了VC1,则还将VC1从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? 从您从一个非常相关的问题的答案之一中可以看到,这实际上也是Apple推荐的方式,在这里可以打开和关闭其他UIViewControllers-除了使用协议和委托之外,还有其他方法吗?

Instead of using modal view controller I have used navigation controller and use push view using CAAnimation instead of present modal view controller 我使用导航控制器,而不是使用模态视图控制器,而是使用CAAnimation来使用推式视图,而不是使用当前的模态视图控制器。

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];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM