How to use custom Navigationcontroller in AppDelegate by using a Storyboard
Asked Answered
H

2

5

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!

Hysterectomize answered 8/1, 2012 at 17:56 Comment(0)
T
8

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.

Tend answered 10/1, 2012 at 18:48 Comment(1)
Thank you. Now it's clear and works :-) (Bounty is only avaible in 10 hours so don't worry ;o))Hysterectomize
M
4

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];
Marjorie answered 10/1, 2012 at 19:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.