2012-12-12 21 views
5

我在我的应用程序中实现了Tab栏控制器。但我的第一页是登录视图。所以,我不想显示标签栏。我通过隐藏该视图上的标签栏来做到这一点。不要显示标签栏Iphone SDK中的第一个登录页面

但现在,当我选择第一个选项卡时,它始终作为登录页面进入rootview控制器。

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

我该如何解决这个问题?

+0

如果我的回答对你有帮助,那么接受和Upvote我的回答亲爱的:) –

回答

0

只是将viewController分配到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; 
+0

shu k bhura kya 6e aajkal ??? tane to dekhata j nathi ne kai ??? –

0

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

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

ps:你可以找到一个小窍门,不写所有条件来为iPhone/iPad加载不同的xib here

0

你必须使用不同的方式来显示你的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。