2012-12-12 33 views
5

Tôi đã triển khai bộ điều khiển thanh tab trong ứng dụng của mình. Nhưng trang đầu tiên của tôi là Chế độ xem đăng nhập. Vì vậy, tôi không muốn hiển thị thanh tab trên đó. Tôi đã làm điều này bằng cách ẩn thanh tab trên chế độ xem đó.Không hiển thị thanh tab từ Trang đăng nhập đầu tiên trong SDK SDK

Nhưng bây giờ, khi tôi đã chọn tab đầu tiên, nó luôn đi tới bộ điều khiển chế độ xem gốc làm trang đăng nhập.

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

Làm cách nào tôi có thể giải quyết vấn đề này?

+0

nếu câu trả lời của tôi hữu ích cho bạn, sau đó chấp nhận và Trả lời câu trả lời của tôi thân yêu :) –

Trả lời

0

chỉ gán viewController cho UINavigationController như dưới đây.

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

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

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

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

và sau đó gán vào thanh tabbar tương tự như mã của bạn ..

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

Hãy nhìn vào giải pháp this.
Về cơ bản, bạn có thể chuyển đổi rootViewController từ loginVC thành tabBarVC sau khi người dùng đã đăng nhập. Nhưng tôi nghĩ rằng các loginVC không nên là "trang đầu tiên" của bạn tabBarVC nhưng shuold là một viewController độc lập.

Nhưng nếu bạn vẫn muốn đăng nhập trong tab đầu tiên, bạn chỉ có thể thay đổi chế độ xem của VC sau khi người dùng đã đăng nhập.
Bạn có thể đặt cờ trong NSUserDefaults để biết người dùng đã đăng nhập như vậy trong viewDidAppear: của tab đầu tiên, bạn có thể kiểm tra xem người dùng đã đăng nhập hay chưa và hiển thị giao diện người dùng khác của bạn.

ps: bạn có thể tìm thấy một mẹo nhỏ để không viết tất cả các điều kiện để tải xib khác nhau cho iPhone/iPad here.

0

Bạn phải sử dụng một cách khác nhau để hiển thị Loginview của bạn mà không tabBarController
Không sử dụng LoginView trên tabBarController.
Bạn phải chọn giá trị boolean như đăng nhập.

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

Sau khi đăng nhập người dùng, bạn có thể đặt đăng nhập = YES.

Các vấn đề liên quan