在我的 iOS 应用程序中,在 viewController 中,我尝试在 Tab Bar Controller 中打开特定 View 。
我使用 performSegue。
首先,我尝试直接导航到特定 View ,但在这种情况下,标签栏消失了
所以我尝试导航到 tabViewController,这将我带到默认 View (第一个)
知道如何导航到 TabBarController 中的特定 View 吗?
我使用的 performSegue:
self.performSegue(withIdentifier: "goToMain", sender: self)
//"goToMain" is my indentipier to the storyboard Segue
I use swift 4
最佳答案
使用这段代码,你不需要转场,你可以在按下某个按钮时使用
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 需要指向标签栏 Controller ,而不是标签栏 Controller 的 View
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
if (segue.identifier == "goToMain") {
let vc = segue.destination as! TabBarController
vc.selectedIndex = 2
}
}
关于ios - 如何从另一个 View (swift 4)对选项卡栏 Controller 中的特定 View 执行 performSegue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59075494/