Search code examples
iosuinavigationcontrollerpush-notificationpushviewcontrolleruiapplicationdelegate

ios: Accessing a navigation controller from app delegate


I have an app that receives push notifications. In didReceiveRemoteNotifications, I would like to make the app show a particular view controller in the app's navigation controller (which happens to be the root view controller). What is the best way to make this happen? Can I get a reference to the navigation controller in the app delegate?

EDIT: Here is the code I'm trying to use right now. It appears to use the correct navigation controller, but it doesn't display the view controller at all, just a blank screen:

        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
        EventDetailViewController *destCon = [storyboard instantiateViewControllerWithIdentifier:@"EventDetailViewController"];
        destCon.event=notifyEvent;
        UINavigationController *navController =(UINavigationController *) self.window.rootViewController;
        [navController pushViewController:destCon animated:YES];

Here is what I'm seeing:

enter image description here


Solution

  • If your navigation controller is the root view controller of the window, then you can just use

    (UINavigationController *)self.window.rootViewController
    

    from the app delegate to access the one you created in the storyboard.