Tab access control is done in AppDelegate, since it owns UITabBarController and UITabBarItems. Just set up delegate handling - and that's the key: either there is a delegate to block tabs or there is none for free access:
@interface MyAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate>Access control can be enabled in any other class/file:
{
UITabBarController *tabBarController;
}
...
- (BOOL)tabBarController:(UITabBarController *)aTabBarController
shouldSelectViewController:(UIViewController *)viewController
{
if (
([aTabBarController.viewControllers objectAtIndex:1] == viewController) ||
([aTabBarController.viewControllers objectAtIndex:2] == viewController)
)
{
// Disable switch to tab 1 and 2
// Check: otherViewController to enable
// Check: SomeViewObject to disable
return NO;
}
else
{
// Tab ok at index 0
return YES;
}
}
- (void)blockTabAccessAccess control can be disabled in any other class/file:
{
MyAppDelegate *app = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
app.tabBarController.delegate = app;
[app SwitchToTab:kTabFirst];
}
- (void)releaseTabAccessSome consider it poor design to access AppDelegate directly from "anywhere" and further more to use it to control application state. My defense are the classic a) it's easy b) it's fast c) it works and d) sometimes central control place is a good thing.
{
MyAppDelegate *app = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
app.tabBarController.delegate = nil;
[app SwitchToTab:kTabSecond];
}
Btw this works only as long as you don't need UITabBarControllerDelegate for any other purpose. You have been warned.