简体   繁体   English

如何在两个视图控制器之间切换

[英]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? 我应该选择哪种类型的视图切换?

  1. presentModal... presentModal ...
  2. addSubview. addSubview。

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 ,因此可能是您可以在其中移动所需的功能并仍然使用模式表示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM