Reputation: 998
Let's say you have an application in which you know for sure that there's always a UINavigationController
displayed, and that I need to display another view controller modally from outside this controller (for example : because I use the Command pattern and I don't want to give a reference to a view controller to it).
Is there a safe way to get the "root" navigation controller, and call its presentModalViewController:animated
method ?
I tried to use [UIApplication sharedApplication].keyWindow.rootViewController
but I figured out that it was nil during an alert.
Upvotes: 0
Views: 619
Reputation: 77631
Are you using a storyboard or separate xibs?
If you're using separate xibs then you will be setting up the UINavigationController
in applicationDidFinishLaunching
.
You can make the navigation controller a property of the app delegate.
Then you can access the UINavigationController from anywhere by getting the singleton app delegate and getting the navigation controller property from it.
Upvotes: 1