First of all, I would like to say that deselecting all tabbaritems is a bad user interface. The chances are high that they will not be accepted in the AppStore.
, , . ( !!!), . Key Value Observing :
- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
mHomeViewController = [[HomeViewController alloc] initWithNibName:nil bundle:nil];
[tabBarController.view addSubview:mHomeViewController.view];
tabBarController.delegate = self;
[tabBarController addObserver:self forKeyPath:@"selectedViewController" options:NSKeyValueObservingOptionNew context:NULL];
}
- (BOOL) tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
if (!mAllowSelectTab)
{
[mHomeViewController.view removeFromSuperview];
mAllowSelectTab = YES;
}
return YES;
}
- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if (!mAllowSelectTab)
{
if (object == tabBarController && [keyPath isEqualToString:@"selectedViewController"])
{
NSNumber *changeKind = [change objectForKey:NSKeyValueChangeKindKey];
if ([changeKind intValue] == NSKeyValueChangeSetting)
{
NSObject *newValue = [change objectForKey:NSKeyValueChangeNewKey];
if ([newValue class] != [NSNull class])
{
tabBarController.selectedViewController = nil;
}
}
}
}
}
:
( ), viewDidLoad viewWillAppear . , , , "" (, , NSNotificationCenter).
EDIT: Apple-UITabbar. UITabbar.