繁体   English   中英

不要在Iphone SDK的第一个登录页面显示标签栏

[英]Don't show Tab bar from first Login Page in Iphone SDK

我在我的应用程序中实现了Tab栏控制器。 但我的第一页是登录视图。 所以,我不想在它上面显示标签栏。 我通过隐藏该视图上的标签栏来完成此操作。

但是现在,当我选择第一个选项卡时,它总是作为登录页面进入根视图控制器。

//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;

我怎么解决这个问题?

只需将viewController m指定给UINavigationController ,如下所示。

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

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

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

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

然后在tabbar中分配与您的代码相同的..

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

看看这个解决方案。
基本上,你可以切换rootViewController从你的loginVCtabBarVC在用户登录后。 但我认为loginVC不应该是你tabBarVC的“第一页”,而是shuold是一个独立的viewController。

但是如果你想要在第一个选项卡中登录,你可以在用户登录后更改VC的视图。
您可以在NSUserDefaults中设置一个标志,以了解用户是否已在viewDidAppear:记录viewDidAppear:在第一个选项卡中,您可以检查用户是否已登录并显示不同的UI。

ps:你可以找到一个小技巧,不写这里为iPhone / iPad加载不同的xib的所有条件。

你必须使用不同的方式来显示你的Loginview没有tabBarController
不要在tabBarController使用LoginView。
您必须选择一个类似登录的布尔值。

- (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
}

用户登录后,您可以设置login = YES。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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