I’m developing an app that can be used without logging in immediately, but certain tabs require login. So I want to have my login view slide up whenever those tabs are opened. If the user hits the Cancel button in the login view, the modal window should be dismissed and it should return to the same view the user was at before. If the login is successful, the window should be dismissed and the tab should load. What’s the best way to implement this? Should I make a custom tab bar controller?
EDIT: I took Caffeine’s approach. This seems to be working for me:
// App delegate
#pragma mark - UITabBarController delegate
- (BOOL)tabBarController:(UITabBarController *)tabBarController
shouldSelectViewController:(UIViewController *)viewController {
if ([[viewController topViewController] loginRequired]) {
LoginViewController *loginViewController = [[LoginViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:loginViewController];
[tabBarController presentModalViewController:navController animated:YES];
[loginViewController release];
[navController release];
return NO;
} else {
return YES;
}
}
You can try implementing the
tabBarController:shouldSelectViewControllerofUITabBarControllerDelegate. Present the modal login controller from within that delegate method and if it’s successful return YES, otherwise NO.