导航到特定的 TabBar 项

Navigate to specific TabBar item

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

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 项目?

提前致谢

编辑:

因为 UITabBarController 是您的应用程序的 rootViewController,假设您知道要切换到的选项卡索引就可以了。

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

在swift 4

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