How to use custom Navigationcontroller in AppDelegate by using a Storyboard

I’ve got a problem concerning Navigationcontroller in AppDelegate. I’m using a storyboard, which looks like this:


  • XCode 8 - IB Designables - Failed to render and update auto layout status, The agent crashed
  • Could not find a storyboard named 'MainStoryBoard' in bundle NSBundle
  • Advantages and disadvantages of using Storyboarding?
  • Xcode storyboard: Internal error. Please file a bug
  • Setting backgroundColor of custom NSView
  • How to connect Xcode Storyboard's “Simulated Metrics” toolbar to an actual IBOutlet UIToolbar?
  • As a result of using Push notifications, i’ve got the following function in my AppDelegate File:

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

    When the notification arrives I want to initialize the “Detail View” – Controller which needs an ID as a parameter. This ID is part of my payload so it is present in didReceiveRemoteNotification.

    I’d like to to the follwing:

    DetailView *detail = [storyboard instantiateViewControllerWithIdentifier:@"detail"];
    detail.conversationID = theID; 
    [self.navigationController pushViewController:detail animated:YES];

    My question at this point is: how can I get the navigation controller? I’ve searched for a function like “getNavigationControllerByIdentifier” or something like this, but found nothing. I can’t instantiate the Detail View Controller directly because the navigationbar is missing there.

    I hope you understand what I mean – if you think my approach is completly wrong please correct me ;o)

    Just another small information: It’s not important for me that the back button in the Detail View Controller goes back to the Table View – it’s enough when it links to the controller with the button “Load Table View”.

    Thank you for help!

    2 Solutions Collect From Internet About “How to use custom Navigationcontroller in AppDelegate by using a Storyboard”

    UINavigationController is a UIViewController subclass and can also be assigned an identifier in the storyboard.

    Use -instantiateViewControllerWithIdentifier: to create the UINavigationController and it’s root view controller. You may need to instantiate all of the intermediate controllers in code and modify the navigation controller’s viewControllers property to set up the appropriate navigation stack. This way when the app launches into the detail view, they can find their way back as if they had manually pushed all the way through via the interface.

    You can use rootViewController on your window object.

    UIViewController *rootViewController = self.window.rootViewController;
    // You now have in rootViewController the view with your "Hello world" label and go button.
    // Get the navigation controller of this view controller with:
    UINavigationController *navigationController = rootViewController.navigationController;
    // You can now use it to push your next view controller:
    DetailViewController *detail = [navigationController.storyboard instantiateViewControllerWithIdentifier:@"detail"];
    detail.conversationID = theID; 
    [navigationController pushViewController:detailViewController animated:YES];