I have a question for you: I have a set of UIViewController attached to self.tabBarController.viewControllers and i have another one alone that is supposed to be the login scree that appear just once (the first time you open the app ever), and i wish to load that one in case the user is not logged in, otherwise or after that the user log in, it will load the full self.tabBarController.viewControllers that i have. Here is the code:
-(void)load_login_view{
NSLog(@"map");
UIViewController * fb_login = [[FacebookLoginView alloc]init];
fb_login.title = @"fsf ss";
UINavigationController * fb_login_navigation = [[UINavigationController alloc] initWithRootViewController:fb_login];
[fb_login_navigation.tabBarItem setImage:[UIImage imageNamed:@"eventi.png"]];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
BOOL login_status = [defaults objectForKey:@"login_status"];
UIViewController * secondpage = [[SecondViewController alloc]init];
secondpage.title = @"second";
UINavigationController * secondpage_navigation = [[UINavigationController alloc] initWithRootViewController:secondpage];
[secondpage_navigation.tabBarItem setImage:[UIImage imageNamed:@"eventi.png"]];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = @[secondpage_navigation];
self.window.rootViewController = self.tabBarController;
if(!login_status){
[self load_login_view];
}else{
}
[self.window makeKeyAndVisible];
}
You have many ways to do that. There is a couple of examples.
-> if the user is not logged, you can display your login view controller as modal so it will be over top of your tabBarController. //something like that
->when you user is logged, dismiss the login controller. If needed, save user data for the next time
->do some work to update the selected controller inside your TabBarcontroller if needed.
-> use
UINavigationController
with the login Controller ([[UINavigationController alloc] initWithRootViewController:fb_login]
) as a rootController for your application-> when you user is logged, push to your TabBarcontroller. If needed, save user data for the next time
->To avoid the double navigationBar (
fb_login_navigation
/secondpage_navigation
), you can hide the navigation offb_login_navigation
when needed.-> the next time, if the user is logged, you can fire the code above just after loading the login controller instead of waiting that the user enters his credentials.
Hope it helps.