0

在我的 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

4

1 回答 1

2

使用此代码,您不需要 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 
    }
}
于 2019-11-27T17:33:54.010 回答