I got TabBar Application with 3 ViewControllers. Can i know from the ViewControllers's method which ViewContoller was desplayed before (1 or 2)? Or maybe i open VeiwController from some other .xib
Asked
Active
Viewed 68 times
2 Answers
3
You can do this by implementing UITabBarController
delegate method -
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
}
in this you can check for [tabBarController selectedViewController]
, here selectedViewController
is the view controller which is currently selected and viewController
is which is going to be selected.

saadnib
- 11,145
- 2
- 33
- 54
-
But i need to know which controller was selected – Eugene Trapeznikov Feb 09 '12 at 13:58
-
1just make a global UIViewController's instance and when you tap on a tab then the above method will call and here set your global var to the value of [tabBarController selectedViewController] and you can check what view controller it is ... – saadnib Feb 09 '12 at 14:15
-
can you explain how should i do it? – Eugene Trapeznikov Feb 09 '12 at 14:16
1
I just creating @property
in target VeiwController
and set this @property firstly in viewDidLoad. So i know that firstly this ViewController will appear from TabBar. After that i can change it in some other ViewController's methods, which call some subviews (.xib).

Eugene Trapeznikov
- 3,220
- 6
- 47
- 74