简体   繁体   English

如何从“菜单”视图控制器在现有UIViewControllers之间导航?

[英]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.

相关问题 如何有条件地选择下一个视图控制器进行导航? - How do I conditionally select the next view controller to navigate to? 如何在使用 SwiftUI 的同时导航到视图 Controller? - How do I navigate to a View Controller while also using SwiftUI? 单击按钮后,如何从视图控制器导航到另一个视图控制器? - How i can navigate from View Controller to another View Controller once clicking on button? 如何在布局类似于叉子的UIViewControllers之间导航和传递数据? - How to navigate and pass data between UIViewControllers whose layout resembles a fork? 如何从一个视图控制器导航到另一个 - How to navigate From one view controller to other 如何从popoverpresentation视图控制器导航到另一个视图控制器 - How to navigate from popoverpresentation view controller to another view controller 如何从一个视图控制器导航到另一视图控制器? - How to navigate from one view controller to another view controller? 如何访问已有的视图控制器 - How do I Access an Already Existing View Controller iOS-目标C-如何从登录视图控制器中删除Tableview菜单? - IOS - Objective C - How do I remove Tableview Menu from my Login View Controller? UITabBar控制器选项卡可导航到不同的UIViewControllers - UITabBar Controller tab to navigate to different UIViewControllers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM