Question

I am writing an iOS application using storyboard.

I created ViewControllerA, ViewControllerB and then embedded ViewControllerA in a UINavigationController on the storyboard.

The app will show ViewControllerA when it is first launched, otherwise it will show ViewControllerB.

I added launch history check code successfully. I am going to set the UINavigationController as the window's rootViewController in the didFinishLaunchingWithOptions method.

The problem is that I cannot get the UINavigationController from the storyboard, so I can't push ViewControllerA and ViewControllerB based on my condition.

Was it helpful?

Solution

If you're using a storyboard then the UINavigationController should be set as the initial view controller and it will be loaded and displayed automatically. Now, when something happens in ViewControllerA it can push ViewControllerB by using:

ViewControllerB *b = ...;
[self.navigationController pushViewController:b animated:YES];

For enhanced tampering, the app delegate has a window property. From here you can get the rootViewController. Cast that to the UINavigationController and you can modify / push. Set it to something else and you can replace the UINavigationController all together.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top