user3359535
user3359535

Reputation: 21

Issue while presenting viewControllers

I have a configurationControllerVC and loginPageControllerVC. Initially I want to present the configurationControllerVC. Once my configuration procedure is completed, I go to the loginControllerVC. If the configuration is already done and the user re-opens the app I want to load the loginControllerVC straight away without having to go through the configuration procedure.

The problem is that in my application, there is one condition and if it is false I want to take the user back to configurationControllerVC.

My flow of viewControllers is as below:

If configuration is not yet Done:

ConfigurationControllerVC --> LoginControllerVC --> HomePageControllerVC --> ReportingControllerVC.

If Configuration is done then the flow is this:

LoginControllerVC --> HomePageControllerVC --> ReportingControllerVC.

The condition on which I want to navigate the user to configurationControllerVC may be encountered on HomePageControllerVC or reportingControllerVC.

In such a case what is better? Using a UINavigationController or just presenting the Views one above the other? Also, how do I achieve this part of navigating the user back to configurationControllerVC?

Currently I am using this code to present the configurationControllerVC and LoginControllerVC in my appDelegate.

if ([self checkForConfiguration]) {

 // Initiate initial screen
    ConfigurationController *configurationController = [[ConfigurationController alloc] initWithNibName:@"ConfigurationPage"
                                                                                                 bundle:nil];

    [self.window setRootViewController:configurationController];
}else{

    LoginController *loginController = [[LoginController alloc] initWithNibName:@"LoginPage" bundle:nil];

    [self.window setRootViewController:loginController];
}

Have seen these links but neither are working in my case:

  1. Changing root view controller of a iOS Window
  2. UINavigation pushing a new root controller

Upvotes: 1

Views: 71

Answers (2)

Tim
Tim

Reputation: 9042

Why not just create a UINavigationController, where the loginController is the rootViewController, where you can then push to the homePageController and reportingController.

And whenever your condition is met for [self checkForConfiguration], present that over the top of the UINavigationController?

[self.navigationController presentViewController:configViewController animated:YES completion:nil];

Upvotes: 1

Wain
Wain

Reputation: 119031

I'm with @Jeff about using a UINavigationController as the window root view controller.

For your 'special' transitions (config -> login, login -> home, any -> config, because you don't want the user to be able to go back), instead of using push or pop, use setViewControllers:animated:. You'll get a nice animation are replace the navigation controllers root view controller.

For your home -> reporting you can just push onto the navigation controller stack as usual.

Upvotes: 0

Related Questions