iPhone - 关闭多个 ViewControllers [英] iPhone - dismiss multiple ViewControllers

查看:21
本文介绍了iPhone - 关闭多个 ViewControllers的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很长的视图控制器层次结构;

I have a long View Controllers hierarchy;

在第一个视图控制器中我使用以下代码:

in the first View Controller I use this code:

SecondViewController *svc = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
[self presentModalViewController:svc animated:YES];    
[svc release];

在第二个视图控制器中,我使用以下代码:

In the second View Controller I use this code:

ThirdViewController *tvc = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];
[self presentModalViewController:tvc animated:YES];    
[tvc release];

等等.

所以有一段时间我有很多视图控制器,我需要回到第一个视图控制器.如果我一次返回一步,我会在每个视图控制器中使用以下代码:

So there is a moment when I have many View Controllers and I need to come back to the first View Controller. If I come back one step at once, I use in every View Controller this code:

[self dismissModalViewControllerAnimated:YES];

如果我想直接从第六个 View Controller 返回到第一个,我必须做些什么才能一次关闭所有控制器?

If I want to go back directly from the, say, sixth View Controller to the first one, what I have to do to dismiss all the Controllers at once?

谢谢

推荐答案

我找到了解决方案.

当然,您可以在最明显的地方找到解决方案,因此请阅读 UIViewController 参考中的dismissModalViewControllerAnimated 方法...

Of course you can find the solution in the most obvious place so reading from the UIViewController reference for the dismissModalViewControllerAnimated method ...

如果您呈现多个模态视图控制器连续,因此构建一堆模态视图控制器,在一个堆栈中较低的视图控制器驳回其直接子视图控制器和所有视图控制器在堆栈上的那个孩子之上.什么时候发生这种情况,只有最顶层的视图以动画方式被解雇;任何中间视图控制器都是简单地从堆栈中删除.这使用它的最高视图被驳回模态过渡风格,这可能不同于其他人使用的样式堆栈中较低的视图控制器.

If you present several modal view controllers in succession, and thus build a stack of modal view controllers, calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. When this happens, only the top-most view is dismissed in an animated fashion; any intermediate view controllers are simply removed from the stack. The top-most view is dismissed using its modal transition style, which may differ from the styles used by other view controllers lower in the stack.

所以在目标视图上调用dismissModalViewControllerAnimated就足够了.我使用了以下代码:

so it's enough to call the dismissModalViewControllerAnimated on the target View. I used the following code:

[[[[[self parentViewController] parentViewController] parentViewController] parentViewController] dismissModalViewControllerAnimated:YES];

回我家.

这篇关于iPhone - 关闭多个 ViewControllers的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆