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

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

问题描述

我有一个很长的View Controllers层次结构;

I have a long View Controllers hierarchy;

在第一个View Controller中我使用此代码:

in the first View Controller I use this code:

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

在第二个View Controller中,我使用此代码:

In the second View Controller I use this code:

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

依此类推。

所以那里我有很多View控制器,我需要回到第一个View Controller。
如果我一次回来一步,我在每个View Controller中使用这段代码:

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天全站免登陆