Marplesoft
Marplesoft

Reputation: 6240

How do you transition in a new non-model view controller without using UINavigationController?

The following seems like a typical use case: You start the app with a LoginViewController that displays the login screen. Once the user has successfully logged in, you want to show the main view for your app (let's call it MainViewController).

You don't want to put the LoginViewController into a UINavigationController and subsequently push MainViewController onto it because there's no reason to keep the LoginViewController present at the bottom of the stack since it will never be shown again. Also, in subsequent launches of the app, you'll determine that you've already got a login token of some kind and will never end up showing the LoginViewController at all so there'd be inconsistency from launch to launch of the navigation controller's stack.

You also don't want to modally present MainViewController from LoginViewController for the same reason (if it's modal it would keep the LoginViewController loaded behind).

You also don't want to set the window's rootViewController to MainViewController (where it was previously set to LoginViewController) because that won't allow you have a transition.

I'd like some feedback on whether my logic above is flawed and in fact one of these scenarios is the right one? Or if not, what are others doing for this scenario?

Upvotes: 1

Views: 997

Answers (2)

rickster
rickster

Reputation: 126107

Why not make the MainViewController your app's root view controller, and present the LoginViewController modally upon launch if you don't have a login token?

Upvotes: 4

nsgulliver
nsgulliver

Reputation: 12671

I have this kind of application and I have implemented by removing the LoginViewController which is the current object and and adding the TabBarController with the HomeViewController on focus like this

  /* remove the  current Login screen and show the 2nd tab */ 
    NSMutableArray* newArray = [NSMutableArray arrayWithArray:self.tabBarController.viewControllers];
    [newArray removeObject:self];
    [self.tabBarController setViewControllers:newArray animated:YES];

when use log out from the app then I create the login screen and add to the stack, otherwise just go directly to the HomeViewController

when use log out from the app then I add the LoginViewController back on the stack and assign the current index of UITabBarController to LoginViewController something like this

 NSMutableArray *array =[NSMutableArray arrayWithObject:loginController];
        NSMutableArray* oldArray = [NSMutableArray arrayWithArray:self.tabBarController.viewControllers];
        [array addObjectsFromArray:oldArray];

        [self.tabBarController setViewControllers:array animated:YES];
        [self.tabBarController setSelectedIndex:0];

        self.tabBarController.tabBar.hidden=YES;

Upvotes: 2

Related Questions