[英]How do I navigate between existing UIViewControllers from a “menu” view controller?
I have a menu view controller with buttons that should take me to a different view controller. 我有一个带有按钮的菜单视图控制器,应该将我带到其他视图控制器。 I do not have a navigation controller in my storyboard.
我的故事板中没有导航控制器。 Currently I transition to new view controllers using segues, both through storyboard as well as programatically.
目前,我通过情节提要和编程方式使用segues过渡到新的视图控制器。 My menu view controller is presented modally when it is called.
我的菜单视图控制器在调用时以模态显示。 How can I navigate to a already instantiated view controller instead of making new ones every time?
如何导航到已实例化的视图控制器,而不是每次都新建一个?
You can do this using Unwind segue. 您可以使用Unwind segue执行此操作。
I assume there are three ViewControllers A(Menu),B and C. Now you press button on A and you moved to B, Now you press button on B and moved to C. 我假设有三个ViewController A(菜单),B和C。现在您按A上的按钮,然后移动到B,现在按B上的按钮,然后移动到C。
Now you wants to come back to ViewController A, 现在您想回到ViewController A,
Step 1: Create this function on ViewController A. 步骤1:在ViewController A上创建此函数。
@IBAction func unwindToViewControllerA(segue:UIStoryboardSegue){
//do your stuff here.
}
Step 2: Suppose you have button on ViewController C ,after clicking on that you wants to come back to ViewController A . 第2步:假设您在ViewController C上有一个按钮,单击后,您想回到ViewController A。
-So go to ViewController C in StoryBoard, -因此,转到StoryBoard中的ViewController C ,
-Ctrl+drag from "Go to A View Controller" button to Orange Exit button as shown in image, -Ctrl +从“转到视图控制器”按钮拖动到“橙色退出”按钮,如图所示,
-And click on unWindToViewControllerA. -然后单击unWindToViewControllerA。
That's it. 而已。
Now after clicking on button "Go to A View Controller" you will go to "ViewController A." 现在,单击“转到视图控制器”按钮后,您将转到“ ViewController A”。
I also recommend to read this Technical note from Apple . 我还建议您阅读Apple的技术说明 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.