Reputation: 17421
I have a basic navigation stack: NavController->UITableViewController (as rootViewController in the NavController) -> menu items with the main option being a custom viewController. I want my app to launch with the main custom view controller as the current view on the navigationController's stack, and the back button to go to the Main Menu. Is there some way using storyboarding to setup the stack this way and yet on launch show the custom view first?
I'm trying to do this in storyboarding as much as possible. I know I could go in the appDelegate and on appDidFinishLaunching... push the custom viewController into the navController but that just seems bad because then in my appDelegate I have to reference the navController and the custom viewController.
Upvotes: 6
Views: 17488
Reputation: 111
While this isn't a storyboard solution per se, the UINavigationController instance method popToViewController:animated: allows you to start your app with a particular view controller as the one being displayed.
I use this one a lot when testing my apps so I don't have to walk through the entire nav stack in order to get to the VC I'm working on!
I'm not sure what you want to do can be done in Storyboard.
H.
Upvotes: 0
Reputation: 30846
Unfortunately UIStoryboard
isn't able to manipulate a UINavigationController
hierarchy in a visual way. In your case, you need to establish the hierarchy programmatically in your application delegate. Luckily, because you are storyboarding, your app delegate already contains a reference to this navigation controller.
When storyboarding, the so called "Initial View Controller" will be wired up to the rootViewController
property on the application's instance of UIWindow
by the time -applicationDidFinishLaunchingWithOptions:
is messaged.
- (BOOL)application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)options
{
UINavigationController *navController = (UINavigationController *)self.window.rootViewController;
MenuViewController *menu = [navController.storyboard instantiateViewControllerWithIdentifier:@"MenuController"];
CustomViewController *custom = [navController.storyboard instantiateViewControllerWithIdentifier:@"CustomController"];
// First item in array is bottom of stack, last item is top.
navController.viewControllers = [NSArray arrayWithObjects:menu, custom, nil];
[self.window makeKeyAndVisible];
return YES;
}
I realize this isn't ideal, but if you want to stay in the land of storyboards, I'm afraid this is the only way.
Upvotes: 17