当Root视图控制器是Tab栏控制器时,如何在UILocalNotification上接收view.xib?

时间:2014-02-07 05:02:07

标签: ios iphone

我试图在我的Appdelegate.m文件中收到我的UILocalNotification时推送View.xib。但我的主根视图控制器是标签栏控制器。

我的代码无效,如下所示:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    application.applicationIconBadgeNumber = 0;  
    UILocalNotification *localNotif = [launchOptionsobjectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
    if (localNotif)  
    {  
        NSLog(@"Recieved Notification %@\n",localNotif);  
    }  
    _window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];  
    _tabBarController = [[AKTabBarController alloc] initWithTabBarHeight:            (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) ? 70 : 50];

    [_tabBarController setViewControllers:[NSMutableArray arrayWithObjects:
                                           navigationController,
                                           navigationController2,
                                           navigationController3,
                                           nil]];  
    [_window setRootViewController:_tabBarController];  
    [_window makeKeyAndVisible];  
    return YES;  
}  


-(void)application:(UIApplication *)application
     didReceiveLocalNotification:(UILocalNotification *)notification     
{    
    NSLog(@"in didReceiveLocalNotification");    
    StartViewController2Track *viewController = [[StartViewController2Track    alloc]initWithNibName:NSStringFromClass([StartVie Controller2Track class]) bundle:nil];    

 //   [self.window.rootViewController presentViewController:viewController animated:YES completion:nil ];    

//    [self.navcontrol pushViewController:viewController animated:YES];

    [self.rootViewController.tabBarController.selectedViewController.navigationController [pushViewController:StartViewController2Track animated]];    

}    

1 个答案:

答案 0 :(得分:0)

你的rootviewcontroller是tabbarController。所以你试图从tabbarcontroller.tabbarcontroller推出,而且selectedViewcontroller也是导航控制器。尝试以下..

[self.window.rootViewController.selectedViewController pushViewController:viewController animated:YES]];