Don’t show Tab bar from first Login Page in Iphone SDK

Don’t show Tab bar from first Login Page in Iphone SDK

I implemented Tab bar controller in my app. But my first page is Login View. So, i don't want to show tab bar on it. I did this by hiding the tab bar on that view.
But Now, When i selected the First tab , it always goes to the rootview controller as a Login Page.
//for home tab..


    UINavigationController *nav1 = [[UINavigationController alloc] init];

    UIViewController *viewController1;
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        viewController1 = [[[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil] autorelease];
    } else
    {
        viewController1 = [[[LoginViewController alloc] initWithNibName:@"LoginViewController_iPad" bundle:nil] autorelease];
    }

    nav1.viewControllers = [NSArray arrayWithObjects:viewController1, nil];



    //for account tab...
    UINavigationController *nav2 = [[UINavigationController alloc] init];
    UIViewController *viewController2;
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        viewController2 = [[[AccountView alloc] initWithNibName:@"AccountView_iPhone" bundle:nil] autorelease];
    } else
    {
        viewController2 = [[[AccountView alloc] initWithNibName:@"AccountView_iPad" bundle:nil] autorelease];
    }
    nav2.viewControllers = [NSArray arrayWithObjects:viewController2, nil];

    //for links tab...
    UINavigationController *nav3 = [[UINavigationController alloc] init];
    UIViewController *viewController3;
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        viewController3 = [[[LinksView alloc] initWithNibName:@"LinksView_iPhone" bundle:nil] autorelease];
    } else
    {
        viewController3 = [[[LinksView alloc] initWithNibName:@"LinksView_iPad" bundle:nil] autorelease];
    }
    nav3.viewControllers = [NSArray arrayWithObjects:viewController3, nil];

    //for about us tab...
    UINavigationController *nav4 = [[UINavigationController alloc] init];
    UIViewController *viewController4;
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        viewController4 = [[[AboutUsView alloc] initWithNibName:@"AboutUsView_iPhone" bundle:nil] autorelease];
    } else
    {
        viewController4 = [[[AboutUsView alloc] initWithNibName:@"AboutUsView_iPad" bundle:nil] autorelease];
    }
    nav4.viewControllers = [NSArray arrayWithObjects:viewController4, nil];


    self.tabBarController = [[[UITabBarController alloc] init] autorelease];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:nav1,nav2,nav3,nav4,nil];

    self.tabBarController.tabBar.tintColor = [UIColor blackColor];

    //self.tabBarController.tabBar.tintColor = [UIColor colorWithRed:237.0/255.0 green:208.0/255.0 blue:0.0/255.0 alpha:1.0];

    self.window.rootViewController=self.tabBarController;

How can i solve this?

Solutions/Answers:

Answer 1:

just assign the viewController mto the UINavigationController like bellow.

UINavigationController *nav1 =[[UINavigationController alloc]initWithRootViewController:viewController1];

UINavigationController *nav2 =[[UINavigationController alloc]initWithRootViewController:viewController2];

UINavigationController *nav3 =[[UINavigationController alloc]initWithRootViewController:viewController3];

UINavigationController *nav4 =[[UINavigationController alloc]initWithRootViewController:viewController4];

and then assign in tabbar same like your code..

self.tabBarController.viewControllers = [NSArray arrayWithObjects:nav1,nav2,nav3,nav4,nil];
self.window.rootViewController = self.tabBarController;

Answer 2:

Take a look at this solution.
Basically you could switch the rootViewController from your loginVC to the tabBarVC after the user has logged. But i think that the loginVC should not be the “first page” of you tabBarVC but shuold be an indipendent viewController.

But if you want anyway the login in the first tab you can just change the view of the VC after the user has logged.
You can set a flag in NSUserDefaults to know if the user has logged so in the viewDidAppear: of the first tab you can check if the user is logged and show your different UI.

ps: you can find a little trick to not write all the conditions to load a different xib for iPhone/iPad here.

Answer 3:

You have to use a different way to show your Loginview without tabBarController
Don’t use LoginView on tabBarController.
You have to choose a boolean value like login.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSUserDefaults *default=[NSUserDefaults standardUserDefaults];
if(![default boolForKey:@"login"])
{
    //here tab is your tabBarController.
    [tab presentViewController:yourLoginView animated:YES completion:nil];
}
else{
    //your normal code
}

After User login you can set login=YES.

References

Loading...