I managed to accomplish this with KVO tricks .
: , UITabBarController selectedViewController .
:
- (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).