导航到特定的TabBar项目

时间:2016-10-23 11:28:40

标签: ios swift uitabbarcontroller tabbar

我有一个功能可以导航我到我想要的任何视图:

func move(identifier: String , viewController : UIViewController)  {
        let mstoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let vc: UIViewController = mstoryboard.instantiateViewController(withIdentifier: identifier)
        viewController.present(vc, animated: true, completion: nil)
    }

如何将其转换为导航到我想要的任何tabBar项目? 或者我可以使用什么来导航我想要的任何tabBar项?

提前致谢

编辑:

enter image description here

enter image description here

2 个答案:

答案 0 :(得分:5)

由于UITabBarController是您的应用程序rootViewController,假设您知道要转换为此标签的标签索引,则可以为您完成。

    let tabBarController = UIApplication.shared.keyWindow?.rootViewController as! UITabBarController
    tabBarController.selectedIndex = tabIndex
    self.presentingViewController!.presentingViewController!.dismiss(animated: true, completion: {})

enter image description here

答案 1 :(得分:0)

快速4

override func viewWillAppear(_ animated: Bool) {
            self.selectedIndex = 3  //enter your tabbar no.
    }