Reputation: 2832
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
Edit:
Upvotes: 3
Views: 5643
Reputation: 755
In swift 4
override func viewWillAppear(_ animated: Bool) {
self.selectedIndex = 3 //enter your tabbar no.
}
Upvotes: 4
Reputation: 2496
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
self.presentingViewController!.presentingViewController!.dismiss(animated: true, completion: {})
Upvotes: 7