如何在appdelegate的标签视图控制器中调用方法。故事板

时间:2012-06-06 19:32:09

标签: objective-c ios

我需要在app委托的选项卡上选择索引,并在视图控制器中调用选项卡映射到故事板中的函数

(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

     NSString *alertMessage = [[userInfo objectForKey:@"aps"] valueForKey:@"alert"];

    if (alertMessage != nil){
         UITabBarController *tabb = (UITabBarController *)self.window.rootViewController;
        tabb.selectedIndex = 2;
     // Need to call a method in my SpecialsViewController which manages properties and functions of tab with index 2
    }
}

1 个答案:

答案 0 :(得分:0)

执行以下操作

UITabBarController *tabb = (UITabBarController *)self.window.rootViewController;
UIViewController *controller = [tabb.viewControllers objectAtIndex:index_of_your_view_ SpecialsViewController];
[controller call_your_method];

在您的情况下index_of_your_view_ SpecialsViewController = 2