A set of rootViewController storyboards from NavController to tableView, but when the application starts, displays a different view

I have a basic navigation stack: NavController-> UITableViewController (like rootViewController in NavController) β†’ menu items, the main option of which is a custom viewController. I want my application to start with the main custom view controller as the current view in the navigationController stack, and the back button to the Main menu. Is there a way to use the storyboard to set the stack this way, but when I start it shows a custom view first?

I try to do this in the storyboard as much as possible. I know that I can go to appDelegate and to appDidFinishLaunching ... click customController viewController in navController, but that just seems bad, because then in my appDelegate application I have to reference navController and customController.

+6
source share
2 answers

Unfortunately, the UIStoryboard not able to visually manipulate the UINavigationController hierarchy. In your case, you need to establish a hierarchy programmatically in the application deletion. Fortunately, because you are storyboards, your application delegate already contains a link to this navigation controller.

In the storyboard, the so-called "initial view controller" will be connected to the rootViewController property in the UIWindow application instance by the time the -applicationDidFinishLaunchingWithOptions: message is -applicationDidFinishLaunchingWithOptions: .

 - (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 understand that this is not ideal, but if you want to stay in the country of the storyboard, I am afraid that this is the only way.

+17
source

Although this is not a solution to the storyboard as such, the instance method of the UINavigationController popToViewController: animated: allows you to launch your application using a specific view controller, as displayed.

I use this a lot when testing my applications, so I don’t have to go through the whole stack to get to the VC I'm working on!

I'm not sure what you want to do, this can be done on the Storyboard.

N.

0
source

Source: https://habr.com/ru/post/903950/


All Articles