swift - 从模态视图转到选项卡栏 View Controller 并且不会丢失选项卡栏

标签 swift segue uistoryboard

你好,我想在不丢失标签栏的情况下从模态切换到标签栏 View Controller ?我知道问题很短,但这就是我要问的全部内容。

场景:我有一个标签栏 View Controller ,A 和 B。B 模态到 C View Controller 。然后我想返回到 View Controller A。

请 swift :D

最佳答案

这是我如何执行此操作的示例。在我的设置中,我从选项卡中选择黄色 ViewController,然后按 Go! 以模态显示 白色 ViewController。按 退出 返回到绿色 ViewController

Storyboard overview


要进行此设置,请使用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 从弹出...

drag from button to Exit enter image description here


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

enter image description here

然后,转到文档大纲 View 并单击unwind segue

enter image description here

并在右侧的 Attributes Inspector 中为其指定一个标识符(例如“returnFromModal”)。

enter image description here

然后您可以像这样调用unwind segue:

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

关于swift - 从模态视图转到选项卡栏 View Controller 并且不会丢失选项卡栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30991551/

相关文章:

Swift:选择 UICollectionViewCell(在 UITableViewCell 内)时如何使用 Segue

ios5 - 未调用 prepareForSegue

ios - 在swift 4中创建一个包含数组和字典的字典

swift Xcode 6 unwind segue Action 不会触发

ios - 停止推送 segue 直到被告知继续前进 - Obj C

ios - 如何知道 segue 是推送还是模态

ios - Storyboard中的主视图尺寸不正确(仅限纵向)

ios - Xcode 5 与 iOS 7 : 'Story Board: There are unexpected subviews in the container view.' 中的 NSInternalInconsistencyException

swift 3(SpriteKit): Create a texture from a node tree

ios - Firebase 云消息传递 iOS : No background push notification