I have a program where we are using a navigation controller and need the app to launch to one of two different views. Basically if certain info has previously been entered then we need the app to launch to view A, but if the info has never been entered then we need it to launch to view B. I am having difficulty getting this to work and am wondering what ways if any I could implement this. I am certain it needs to be done in the app delegate but I am not sure how. Thanks in advance!
From your question, it sounds as though your UINavigationController is defined inside a XIB along with your root view controller. In that case, you will need to load the appropriate view from within application:didFinishLaunchingWithOptions:
of your App Delegate. From there, you can set the first view controller for the UINavigationController using setViewControllers:animated:
.
I have met this issue and solved it.
In you navigation controller build a container view.
Then depending on your conditions you decided what view to put in the container. You might have built these two views beforehand. Then, you can add the view into the container view. I think the "Elements" sample has an example of the container view.
Implement the following method in your app delegate.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[window makeKeyAndVisible];
if(condition) {
[window addSubview:[mainViewControllerA view]];
} else {
[window addSubview:[mainViewControllerB view]];
}
}
There you can choose which view to load depending on your condition.