mike vorisis mike vorisis - 6 months ago 40
iOS Question

Navigate to specific TabBar item

I have a function that navigates me to whatever view I want:

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)

How can I convert it to navigate me to whatever tabBar item I want?
Or what can I use to navigate at whatever tabBar item I want?

Thanks in advance


enter image description here

enter image description here


Since UITabBarController is your application's rootViewController, assuming that you know tab index you want to switch to this will do for you.

    let tabBarController = UIApplication.shared.keyWindow?.rootViewController as! UITabBarController
    tabBarController.selectedIndex = tabIndex

enter image description here