Search code examples
xcodeuinavigationcontrollerapple-push-notificationsxcode-storyboard

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:

Storyboard

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!


Solution

  • 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.