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?
views:
61answers:
2You 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.)
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.