UIViewControllers - View1,View2,View3连续显示 [英] UIViewControllers - View1, View2, View3 displayed in succession

查看:86
本文介绍了UIViewControllers - View1,View2,View3连续显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要连续显示三个UIViewControllers。 UIViewController1是我的主视图控制器,并有一个按钮。单击按钮以模态方式显示UIViewController2。 30秒后,UIViewController3以模态自动显示。我是否必须首先dimiss UIViewcontroller2,然后显示UIViewController3?。我在UIViewcontroller3上有一个Done按钮,然后点击它就会把我带回UIViewController1(主视图控制器)。我是否先从链中解除UIViewController2,然后在UIViewController1上执行alloc / init来显示它?我不希望在此过程中出现任何内存泄漏。

I have three UIViewControllers that I need to show in succession. The UIViewController1 is my main view controller and has a button. Clicking on the button displays UIViewController2 modally. After 30 seconds, UIViewController3 is automatially shown modally. Do I have to first dimiss UIViewcontroller2 and then display UIViewController3?. I have a Done button on UIViewcontroller3 and clicking on it should take me back to UIViewController1 (main view controller). Do I have first dismiss UIViewController2 from the chain and then do a alloc/init on UIViewController1 to show it?. I don't want to get any memory leaks in this process.

请帮忙。

推荐答案

有两种主要方法可以做到这一点,其中一种方法,你提到过。在XCode中测试这个场景之后。

There are two main ways that you can do this, one of which, you have alluded to. After testing this scenario in XCode.

第一个涉及从最终视图控制器中解除所有模态视图控制器(第三个)。通过这样做,您不能使用动画来关闭视图控制器。如果你试图给它们制作动画,那么第二个就不会被解雇。 (当然,您可以通过动画解散第二个动画,但它会显示动画从第二个到第一个,而不是从第三个到第一个

The first involves dismissing all modal view controllers from the final view controller (the third). By doing this, you cannot use animation to dismiss the view controllers. If you try to animate them, the second will not be dismissed. (Granted, you could dismiss the second one with animation, but it would display the animation from the second to the first, rather than from the third to the first)

要执行此操作,您需要将第二个视图控制器作为属性传递给第三个视图控制器,以便您可以调用该行:

To do this, you'll need to pass your second view controller as a property to your third view controller so you can call the line:

[[self parentVC] dismissModalViewControllerAnimated:NO];

请注意,parentVC是应设置为指向第二个视图控制器的属性

然后在解雇时:

[self dismissModalViewControllerAnimated:NO];
[[self parentVC] dismissModalViewControllerAnimated:NO];

这将带你回到第一个视图控制器。

This will take you back to the first view controller.

第二个,不是更好或更糟,但可能更容易编码,是在第三个之前解雇第二个视图控制器;再次,您可能不希望在从第二个到第三个的过渡之间为视图控制器设置动画,但是可以第三个到第一个进行动画处理。

The second, which is not really better or worse, but is probably easier to code, is to dismiss the second view controller before going to the third; again, you probably will not want to animate the view controllers between the transition from the second to the third, but you could animate from the third to the first.

这篇关于UIViewControllers - View1,View2,View3连续显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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