Reputation: 93
In case I have 4 items in Tabar.
When open app, default is in TabBarItem[0] - ViewControllerRoot I push from ViewControllerRoot into ViewController A. From ViewController A, I switch to TabBarItem[3] - contain ViewController B.
The question is: How can I get name of ViewController A when I switch to TabBarItem[3]?
Thank you so much.
Upvotes: 1
Views: 915
Reputation: 336
Your question is a bit unclear..please share some code.
window.rootViewController?.childViewControllers[0]
a = window.rootViewController?.childViewControllers[0]
var className: String = a.self
Upvotes: 0
Reputation: 462
You can get your current viewcontroller using selectedViewController.
User delegate method of tabbar.
func tabBarController(_ tabBarController :UITabBarController, shouldSelect: UIViewController){
let currentVC = tabBarController.selectedViewController
let destinationVC = shouldSelect
}
I hope this will work for you.
Upvotes: 4
Reputation: 23
When you change the view from UITabBar there is a delegate method that is invoked
tabBarController:animationControllerForTransitionFromViewController:toViewController:
This will help you to find the previous selected controller.
Upvotes: 0