繁体   English   中英

如何从另一个视图对 Tab Bar Controller 中的特定视图执行 performSegue (swift 4)

[英]How to do a performSegue to a specific view in Tab Bar Controller from another view (swift 4)

在我的 iOS 应用程序中,在viewController 中,我尝试在Tab Bar Controller 中打开特定视图。
我使用performSegue。
首先,我尝试直接导航到特定视图,但在这种情况下,标签栏消失了
所以我尝试导航到 tabViewController,这导致我进入默认视图(第一个)

知道如何导航到 TabBarController 中的特定视图吗?

我使用的 performSegue:

self.performSegue(withIdentifier: "goToMain", sender: self)
//"goToMain" is my indentipier to the storyboard Segue

我使用 swift 4

使用此代码,您不需要segues,您可以在按下某个按钮时使用

let VC1 = self.storyboard!.instantiateViewController(withIdentifier: "tabBarController") as! tabBarLoginViewController
VC1.selectedIndex = 2 //this line says that the view that appears will be third of you tab bar controller
self.navigationController!.pushViewController(VC1, animated: true)

如果你想使用segue使用这个,segue需要指向标签栏控制器,而不是标签栏控制器的视图

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
    if (segue.identifier == "goToMain") {
    let vc = segue.destination as! TabBarController
    vc.selectedIndex = 2 
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM