简体   繁体   中英

Add UINavigationController to navigation stack

I have two UINavigationControllers like this:

LoginNavigationController -> LoginView
HomeNavigationController -> HomeView -> ...

From LoginView I navigate to HomeView modally like this:

[self presentViewController:HomeNavigationController animated:YES completion:nil];

When the app goes to background I use an observer in LoginView that dismisses HomeNavigationController.

There is a case though, in which I must present HomeNavigationController directly, without asking the user to login. I do this from another storyboard and reset my root view controller:

AppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
UIStoryboard *secondStoryboard = [UIStoryboard storyboardWithName:kStoryMain bundle:nil];
UINavigationController *homeViewController = (UINavigationController *)[secondStoryboard instantiateViewControllerWithIdentifier:kControllerHomeNavigation];
appDelegate.window.rootViewController = homeViewController;
[appDelegate.window makeKeyAndVisible];

But when the app goes to background, I still must redirect to LoginView.

Is there a way to redirect to LoginNavigationController, add the observer and present modally the HomeNavigationController, and all this to happen seamlessly for the users, without them noticing that Login is being created? If not, should I somehow change my approach to the task?

You can use this approach to get the required results seamlessly,

1) Make HomeNavigationController as the root view controller of your app.

2) In the first view of HomeNavigationController say it HomeViewController , override viewWillAppear and check if you need to show login view ( You may check this by putting any flag to true when user enters to background or something).

3) If you need to show the LoginNavigationController ,show it as modal without animation like,

[self presentViewController: LoginNavigationController animated:NO completion:nil];

Please let me know if you find something confusing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM