2012-12-12 50 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。