0

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.

VitDuck
  • 83
  • 9
  • Your question is unclear. What you trying to achieve ? – Prashant Tukadiya Apr 25 '18 at 05:05
  • Are you embedding navigation controller in tabbar controller? – Catherine Apr 25 '18 at 05:11
  • If your inside ViewController A the name of it is ViewController A. This question isn't clear. Are you automatically switching to TabBarItem[3] once you land on ViewController A or once your on ViewController A you manually press the 4th tab and switch to it? – Lance Samaria Apr 25 '18 at 05:17
  • @PrashantTukadiya I want to get name of ViewController A when/before I switch from ViewController A to TabBarItem[3]. I edited the original post. – VitDuck Apr 25 '18 at 06:06
  • @SuganyaMarlin yes i embeded navigation controller in tabbar controller – VitDuck Apr 25 '18 at 06:06

3 Answers3

3

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.

Maulik Kundaliya
  • 452
  • 3
  • 17
0

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.

0

Your question is a bit unclear..please share some code.

  • if you wish to get an the instance of ViewController A: window.rootViewController?.childViewControllers[0]
  • if you wish to get the class name of ViewController A:

a = window.rootViewController?.childViewControllers[0] var className: String = a.self

Prashant
  • 336
  • 3
  • 18