从模态视图转到标签栏视图控制器而不丢失标签栏 [英] Segue from modal view to tab bar view controller and not lose tab bar

查看:27
本文介绍了从模态视图转到标签栏视图控制器而不丢失标签栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我试图在不丢失标签栏的情况下从模态切换到标签栏视图控制器?我知道问题很短,但这就是我要问的全部.

Hello Im trying to segue from a modal to a tab bar view controller without losing the tab bar? I know the question is short, but this is all I'm asking.

场景:我有一个标签栏视图控制器,A 和 B.B 模式到 C 视图控制器.然后我想回到视图控制器A.

Scenario: I have a Tab Bar View Controllers, A and B. B modals to C view controller. Then I want to return to View Controller A.

斯威夫特请:D

推荐答案

以下是我如何执行此操作的示例.在我的设置中,我从选项卡中选择 yellow ViewController,然后按 Go! 以模态呈现 白色 ViewController.按 Exit 返回绿色 ViewController.

Here is my example of how to do this. In my setup, I choose the yellow ViewController from the tab, then press Go! which modally presents the white ViewController. Pressing Exit returns to the green ViewController.

要进行设置,请使用 unwind segue 返回调用您的 viewController.例如,在选项卡的第一个 ViewController(调用 modal segue 的那个)中实现这一点.

To set this up, use an unwind segue to return to the viewController that called you. For instance, implement this in the first ViewController of the tab (the one calling the modal segue).

@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-从模态视图控制器中的按钮拖动到视图控制器顶部的 exit 图标,然后选择 backFromModal 从弹出...

Then switch to another tab using self.tabBarController?.selectedIndex = n where n is the number of the tab you really want to go to. To set up the unwind segue, you can either control-drag from a button in your modal view controller to the exit icon at the top of the viewController and select backFromModal from the pop up...

您可以通过control设置以编程方式调用展开segue-从模态viewController顶部的viewController图标拖到exit 图标,然后从弹出窗口中选择 backFromModal.

you can set up the unwind segue to be called programmatically by control-dragging from the viewController icon at the top of the modal viewController to the exit icon, and select backFromModal from the pop up.

然后,转到文档大纲视图并点击unwind segue

并在右侧的属性检查器中给它一个标识符(例如"returnFromModal").

and give it an identifier in the Attributes Inspector on the right (for example "returnFromModal").

然后你会像这样调用unwind segue:

self.performSegue(withIdentifier: "returnFromModal", sender: self)

这篇关于从模态视图转到标签栏视图控制器而不丢失标签栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆