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:
Overview. Use a navigation controller delegate (a custom object that implements this protocol) to modify behavior when a view controller is pushed or popped from the navigation stack of a UINavigationController object.
The app delegate is effectively the root object of your app, and it works in conjunction with UIApplication to manage some interactions with the system. Like the UIApplication object, UIKit creates your app delegate object early in your app's launch cycle so it's always present.
Under the View menu, select Utilities→Show Object Library. In the Object Library, find the Navigation Controller object (see Figure 4-7) and drag and drop it into the storyboard, to the left side of your existing view controller (Figure 4-6). Now you will see something similar to Figure 4-8.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With