salocinx
salocinx

Reputation: 3823

iOS: Why is the navigation bar not shown?

my app starts either to a login view or to the main menu, depending whether the user logged in in a previous session. That's why I define the "initial view controller" programmatically.

The login scene is the root view controller of the navigation controller and from there the user has the option to register or login.

The problem is, that if use the following code, the login view is in fact shown, but the navigation bar is missing... Any ideas what I am doing wrong? All works fine if I declare the login scene in Interface-Builder as the "initial view controller", but I do need to show the view programmatically.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    self.window.rootViewController = [storyboard instantiateViewControllerWithIdentifier:@"LoginScene"];
}

Upvotes: 0

Views: 58

Answers (1)

jrisberg
jrisberg

Reputation: 764

If the LoginScene is the root view controller of the navigation controller, then you should be setting the nav controller as the window's root if I'm understanding correctly:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    self.window.rootViewController = [storyboard instantiateViewControllerWithIdentifier:@"LoginNavController"];
}

Upvotes: 2

Related Questions