Muiltple Modal UIViewControllers |仅关闭顶级模态UIViewController

时间:2014-02-06 11:17:21

标签: ios objective-c uiviewcontroller uinavigationcontroller modalviewcontroller

我的UIViewController堆栈如下所示:

+------ UIViewController_C (presented)
+---- UIViewController_B (presented)
+-- UIViewController_A (pushed)

当我在-dismissViewController:animated上致电UIViewController_C时,UINavigationController会同时取消 <{strong> UIViewController_CUIViewController_B两个文档。 _C上的动画,_B上没有。

解除_C 的最合规方式是什么?

2 个答案:

答案 0 :(得分:0)

尝试如下

在推送到UIViewController_A后出现UIViewController_B,如下面的代码。

UIViewController_B *bbp=[[UIViewController_B alloc]initWithNibName:@"UIViewController_B" bundle:nil];
UINavigationController *passcodeNavigationController = [[UINavigationController alloc] initWithRootViewController:bbp];
passcodeNavigationController.navigationBar.hidden=YES;
[self.navigationController presentModalViewController:passcodeNavigationController animated:YES];
[passcodeNavigationController release];

现在从UIViewController_B尝试在UIViewController_C中出现如下代码。

    UIViewController_C *bbp=[[UIViewController_C alloc]initWithNibName:@"UIViewController_C" bundle:nil];
UINavigationController *passcodeNavigationController = [[UINavigationController alloc] initWithRootViewController:bbp];
passcodeNavigationController.navigationBar.hidden=YES;
[self.navigationController presentModalViewController:passcodeNavigationController animated:YES];
[passcodeNavigationController release];

视图控制器的每个后退按钮的最后和最后一个事情都写在代码行下面。

[self dismissModalViewControllerAnimated:YES];

如果你想要比下面的评论更多的帮助。

答案 1 :(得分:0)

一个解决方案:

模态提供的

UIViewControllers不一定是deallocated - dismissViewController:animated

这意味着,通过将引用传递到UIViewController_A_B_C,您可以为相应的{{1}调用-presentViewController:animated-dismissViewController:animated }通过UIViewControllers

<强>代码:

<强> 1。 UIViewController_B

UIViewController_A

<强> 2。 UIViewController_C

- (void) showUIViewController_C {

    [self dismissViewControllerAnimated:TRUE completion:^{
        UIViewController_C *controller_C = [[UIViewController_C alloc] init];
        controller_C.parentController = self;
        [self.parentController controller_C animated:TRUE completion:nil];
    }];
}

我使用- (void) dismissUIViewController_C { [self dismissViewControllerAnimated:TRUE completion:^{ [self.parentController.parentController presentViewController:self.parentController animated:TRUE completion:nil]; }]; } 作为您之前在堆栈上*parentController的任何类的命名约定。

它简要地回到UIViewController因为我在完成块中调用了UIViewController_A-dismiss,但实际上看起来很有趣。