ios - 如何从另一个 View (swift 4)对选项卡栏 Controller 中的特定 View 执行 performSegue

标签 ios swift swift4 nstabviewcontroller

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

相关文章:

ios - 傻瓜式自定义函数的 CompletionHandler

ios - 如何始终在 Safari 中打开 google plus 登录屏幕

ios - 使用 swift 在 webview 页面中查找文本?

ios - swift -4 : How to fetch data using POST request with Parameters in URLSession with "Content-Type" : "application/x-www-form-urlencoded"

ios - 导入json文件到对象错误

html - 控制 iOS Mobile Safari 和/或 UIWebView 中的文本选择行为?

xcode - 如何在 Swift 中初始化 ALAssetsGroupType 常量?

ios - 为什么我的框架包含 .framework 文件时出错

json - 如何使用 Swift Decodable 协议(protocol)解析 JSON API 结构中的几个硬编码键?

arrays - 从核心数据 Swift 4 中检索数组(可转换)