我在我的 appDelegate 中实例化了一个 UITabBarController,但我需要一种方法来了解用户何时按下不同的标签栏项目(标签栏上的按钮)。
-UITabBarDelegate 协议进行救援(使用所需的 didSelectViewController 方法)!
在 Interface Builder 中连接所有内容后,如何获得对与按下的此选项卡栏项对应的实际 UIViewController 子类实例的引用?
我需要这个参考,因为每次按下标签栏项目时,我都需要在我的 UIViewControllers 子类之一中调用一个方法。
有什么建议么?
- (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
}
}