views:

61

answers:

2

In Obj-C / iOS. Our UI design calls for an initial screen with options to register or log on. After doing either of these, the user data is saved to the phone and a the tabBarController is shown. However, tapping on the tabBar at the bottom takes the view back to the "log on or register" screen. Is it possible to change the root view controller in a tabBarItem's hiearchy?

+1  A: 

You can't change the root, but you can solve this a few ways. Perhaps the simplest is in your viewWillAppear method check to see if the user is logged in, if so, immediately load (using navigation controller, modally or just add a subView depending on your app's structure), the regular logged in view without animation, then the user will never see that this happened. (You might choose to do it the other way, only load the login screen if the user is NOT logged in.)

joelm
I tried -(void)viewWillAppear:(BOOL)animated{ self.navigationController.navigationBar.hidden = TRUE; HideableTabBarController *tbc = (HideableTabBarController *)self.tabBarController; [tbc hideTabBar:YES animated:NO]; NSLog(@"isUserValid: %d",self.isUserValid); if (self.isUserValid == TRUE){ MyViewController *viewController = [[MyViewController alloc] initWithStyle:UITableViewStylePlain User:self.user Events:self.processedEvents]; viewController.hidesBottomBarWhenPushed = NO; [self.navigationController pushViewController:viewController animated:NO]; [viewController release];
quantumpotato
Logging in automatically works fine, thanks for pointing out the animated:NO for the pushVieWController. If I go back, my navbar hiearchy screws up: the nav bar stays up top, but the view doesn't change.
quantumpotato
Pushing a view before a view animation is likely to confuse the navigation controller; it's much more likely to work in `viewDidAppear:`.
tc.
+2  A: 

What you have to do is have a UIViewController called "LoginViewController" as your Root Controller but this controller does not have a UITabBar it's just a controller with the Login UIView. And also have your UITabBarController with all of its content set but don't include the Login just have your basic content.

After the user logs in you show the UITabBarController with its content.

-(void) LoginUser {
      // Load UITabBarController
      YourAppDelegate *app = (YourAppDelegate*)[[UIApplication sharedApplication] delegate]; 
      [app.window addSubview:aTabBarController.view];
}

where app is your *app Delegate.

JeremySpouken