ios - 导航到特定的 TabBar 项

标签 ios swift uitabbarcontroller tabbar

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

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

最佳答案

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

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

enter image description here

关于ios - 导航到特定的 TabBar 项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40202390/

相关文章:

iphone - PhoneGap + Landscape : SplashScreen Loads Properly, 然后在闪烁和消失之前短暂旋转

ios - 识别 iOS View Controller 类型

ios - 集成 iBeacon 和 core蓝牙外设

ios - 初始 View 控件中的 PrepareforSegue

ios - 设置导航 Controller 的初始 View Controller

ios - 如何使用 IBAction 清除 UITextField 中的文本?

ios - Swift @escaping 仅适用于非空函数参数?

ios - 如何防止 UITableView 重用自定义单元格 Swift

ios - 在没有将 isRemovedOnCompletion 设置为 false 的情况下保留动画的 stokeEnd 更改

ios - 如何将 tabBarController 设置为 rootViewController