你好,我想在不丢失标签栏的情况下从模态切换到标签栏 View Controller ?我知道问题很短,但这就是我要问的全部内容。
场景:我有一个标签栏 View Controller ,A 和 B。B 模态到 C View Controller 。然后我想返回到 View Controller A。
请 swift :D
最佳答案
这是我如何执行此操作的示例。在我的设置中,我从选项卡中选择黄色 ViewController,然后按 Go! 以模态显示 白色 ViewController。按 退出 返回到绿色 ViewController。
要进行此设置,请使用unwind segue 返回调用您的viewController。例如,在选项卡的第一个 ViewController 中实现它(调用模式转场的那个)。
@IBAction func backFromModal(_ segue: UIStoryboardSegue) {
print("and we are back")
// Switch to the second tab (tabs are numbered 0, 1, 2)
self.tabBarController?.selectedIndex = 1
}
然后使用 self.tabBarController?.selectedIndex = n
切换到另一个选项卡,其中 n
是您真正想要转到的选项卡的编号。要设置展开转场,您可以control-从模态视图 Controller 中的按钮拖动到viewController 顶部的exit 图标,然后选择 backFromModal
从弹出...
或
您可以通过 control 将 unwind segue 设置为以编程方式调用 - 从模态 viewController 顶部的 viewController 图标拖动到 exit 图标,然后从弹出窗口中选择 backFromModal
。
然后,转到文档大纲 View 并单击unwind segue
并在右侧的 Attributes Inspector 中为其指定一个标识符(例如“returnFromModal”
)。
然后您可以像这样调用unwind segue:
self.performSegue(withIdentifier: "returnFromModal", sender: self)
关于swift - 从模态视图转到选项卡栏 View Controller 并且不会丢失选项卡栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30991551/