2012-06-06 43 views
0

我需要从应用程序的委托选项卡上选择索引并调用视图控制器的功能,该选项卡中的故事板如何在appdelegate的选项卡视图中调用控制器。故事板

(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 
    } 
} 

回答

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

+0

UITabBarController * tabb =(UITabBarController *)self.window.rootViewController; tabb.delegate = self; UIViewController * controller = [tabb.viewControllers objectAtIndex:2]; if(controller!= nil){controller LoadSpecialsWebsite]; } –

+0

继承人我的代码AppDelegate.m但我得到这个错误: - [UINavigationController的LoadSpecialsWebsite]:无法识别的选择发送到实例 的UITabBarController *塔布=(*的UITabBarController)self.window.rootViewController; 的UIViewController *控制器= [tabb.viewControllers objectAtIndex:2]; if(controller!= nil){controller LoadSpecialsWebsite]; } //SpecialsViewController.m - (无效)LoadSpecialsWebsite { 的NSLog(@ “LoadSpecialsWebsite”); } –

+0

确定执行以下操作 的UITabBarController *塔布=(的UITabBarController *)self.window.rootViewController; UINavigationController * controller = [tabb.viewControllers objectAtIndex:2]; if(controller!= nil){[controller.viewControllers.lastObject LoadSpecialsWebsite]; } // // SpecicalViewController.m - (void)LoadSpecialsWebsite {NSLog(@“LoadSpecialsWebsite”); } –

相关问题