2012-06-06 46 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」); } –

相關問題