0

我在我的 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
    }   
}
4

1 回答 1

0

可能我没有正确理解您的问题,但您所要求的似乎只是传递给您提到的方法调用的“viewController”参数

- (void)tabBarController:(UITabBarController *)theTabBarController didSelectViewController:(UIViewController *)viewController

UITabBarController 也有一个属性来获取相同的信息

@property(nonatomic, assign) UIViewController *selectedViewController
于 2010-09-23T02:07:23.180 回答