简体   繁体   English

Swift-从ViewController Segue到UITabBarController页面

[英]Swift- Segue to UITabBarController page from ViewController

I have a UITabViewController in my app. 我的应用程序中有一个UITabViewController On the third ViewController of the UITabViewController , the user is able to go to a separate ViewController outside of the UITabViewController . UITabViewController的第三个ViewController上,用户可以转到UITabViewController之外的单独的ViewController But, when they segue back, the UITabView bar doesn't show. 但是,当他们回头看时,不会显示UITabView条。 So, I made a segue back to the UITabViewController but now it just goes to the first page of the UITabViewController instead of the 3rd. 因此,我对UITabViewController进行了UITabViewController但现在它只转到UITabViewController的第一页,而不是第三页。 I have a prepareForSegue() on the separate ViewController file telling it to go to the 3rd page but it doesn't seem to be working. 我在单独的ViewController文件上有一个prepareForSegue(),告诉它转到第3页,但它似乎不起作用。 Here is my code: 这是我的代码:

func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if(segue.identifier == "tabBarShow"){
        if let tabVC = segue.destination as? UITabBarController {
            tabVC.selectedIndex = 2
            let tabBarController = storyboard?.instantiateViewController(withIdentifier: "TabBarC‌​ontroller") as! UITabBarController
            tabBarController.selectedViewController = tabBarController.viewControllers![2]
        }
    }
}

Does anyone know how to solve this? 有谁知道如何解决这个问题? Any help would be immensely appreciated. 任何帮助将不胜感激。 Thanks so much in advance!! 提前非常感谢!

Cheers, Theo 干杯,西奥

Have you tried: 你有没有尝试过:

@IBAction func backTouched(sender: AnyObject) {
        dismissViewControllerAnimated(true, completion: nil)
}

linking that up in the controller you want to dismiss? 将其链接到您要关闭的控制器中? Or using the func unWindToSegue(segue: ...) method? 还是使用func unWindToSegue(segue:...)方法?

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

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