StuartM
StuartM

Reputation: 6823

UINavigationController not pushing view controller

I have created an application that has a Login.

It starts with a Welcome View Controller, checks if the user is logged in if not, opens a Login View Controller. If the user is logged in, or once they have it pushes the user to the Home View Controller like this.

App Delegate (did finish launching)

self.welcomeViewController = [[APPWelcomeViewController alloc] init];
self.homeViewController = [[APPHomeViewController alloc] initWithNibName:@"APPHomeViewController" bundle:nil];

self.navController = [[UINavigationController alloc] initWithRootViewController:self.welcomeViewController];
self.navController.navigationBarHidden = YES;

self.window.rootViewController = self.navController;

Once the user is logged in it pushes the home view.

// Push the homeViewController onto the navController
[self.navController pushViewController:self.homeViewController animated:YES];

This all works fine up to this point. I then use a modal view controller for the Setting, which includes a button to Logout. The logout of the user runs this:

// Log the user out
[User logOut];

// Then we need to remove the Settings Modal View Conrtoller
[self.presentingViewController dismissModalViewControllerAnimated:YES];

// Then we need to take user back to welcomeViewController
[self.navigationController pushViewController:welcomeViewController animated:YES];

It dismisses the Settings View controller as expected, but the navigation controller remains on the Home view. There is no error, does anyone know why this is not working correctly?

Upvotes: 0

Views: 1784

Answers (3)

StuartM
StuartM

Reputation: 6823

Resolved by re-arranging code. Searching for current user on the appdelegate instead then either loading the nav controller with the root controller of home view or running a method to load the welcome view controller.

The welcome view controller then checks for user as well, if not current user it presents the modal login view controller

Upvotes: 1

Peter Warbo
Peter Warbo

Reputation: 11728

Try this:

// Take me back to the root navigation view controller (APPWelcomeViewController)
[self.navigationController popToRootViewControllerAnimated:YES];

Upvotes: 0

Juan Munhoes Junior
Juan Munhoes Junior

Reputation: 895

you dont need to push navigation controller, once you init your window with the navigation controller that contain the welcome view controller.

if you want to add more view inside this stack (inside welcome view controller) you call method self.navigation controller pushviewcontroller ... if you want to remove from stack, call popviewcontroller..you ll go to your main view stack (root).

Upvotes: 0

Related Questions