[英]How to switch between two view controllers
I have two UIViewControllers
, vc1 and vc2. 我有两个
UIViewControllers
,vc1和vc2。
I want to switch between them. 我想在它们之间切换。 But before loading the view of the new view controller, I want to destroy/release/remove (I'm not sure abt the correct word to use here) the previous viewcontroller.
但是在加载新视图控制器的视图之前,我想销毁/释放/删除以前的viewcontroller(我不确定这里使用的单词正确)。
For example, when I am switching to vc2 from vc1 ,I want to destroy vc1 completely, so that when I return to vc1 from vc2, vc1 will be loaded from scratch (ie viewDidLoad
will be executed). 例如,当我从vc1切换到vc2时,我想完全销毁vc1,以便当我从vc2返回vc1时,将从头开始加载vc1(即,将执行
viewDidLoad
)。
Which type of view switching should I opt for? 我应该选择哪种类型的视图切换?
I am not using a navigation controller. 我没有使用导航控制器。
Currently I am using the presentModal... method, but when I use dismissModalViewcontroller
on the newly presented view controller, it doesn't show up a new instance of the previous view controller. 当前,我正在使用presentModal ...方法,但是当我在新显示的视图控制器上使用
dismissModalViewcontroller
时,它不会显示先前视图控制器的新实例。 Instead, it shows the already running instance of it. 而是显示它已经在运行的实例。
I want the viewDidLoad
method of the previous view controller to run when I dismiss the newly presented view controller. 当我关闭新显示的视图控制器时,我希望运行前一个视图控制器的
viewDidLoad
方法。
What exactly needs to happen in viewDidLoad
? 在
viewDidLoad
到底需要发生什么?
You also have viewWillAppear
available to you, so it could be that you could move the required functionality there and still use the modal presentation. 您还可以使用
viewWillAppear
,因此可能是您可以在其中移动所需的功能并仍然使用模式表示。
See this answer. 看到这个答案。 You can do this with or without animation.
您可以使用或不使用动画来执行此操作。
Animate change of view controllers without using navigation controller stack, subviews or modal controllers? 在不使用导航控制器堆栈,子视图或模式控制器的情况下对视图控制器进行动画更改?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.