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 itHomeViewController
, overrideviewWillAppear
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,Please let me know if you find something confusing.