I have a UITabBarController instansiated in my appDelegate, but I need a way to know when the user presses the different tab bar items (buttons on the tab bar).
-UITabBarDelegate protocol to the rescue (with the required didSelectViewController-method)!
With everything wired up in Interface Builder, how do I obtain a reference to the actual UIViewController subclass instance that corresponds to this tab bar item that was pressed?
I need this reference because I need to call a method in one of my UIViewControllers subclasses every time that tab bar item is pressed.
Any suggestions?
- (void)tabBarController:(UITabBarController *)theTabBarController didSelectViewController:(UIViewController *)viewController
{
NSLog(@"%@", [[self.tabBarController selectedViewController] nibName]); // nil, no success here
if ([theTabBarController selectedIndex] == 1) {
MySecondViewController *reference = (MySecondViewController *) viewController;
if ([reference isKindOfClass:[UINavigationController class]]) {
NSLog(@"OMG. It's a UINavigationController class??!"); // kicks in for some reason, shouldn't reference be a MySecondViewController
}
}