Unhighlight uitabbaritem in uitabbarcontroller

I have a UITabBarController with 5 buttons on a panel. In some activity I want to highlight all the elements of tabulation.

Can anyone help?

Thank,

Ankita p>

0
source share
1 answer

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 {     
    // Create the view controller which will be displayed after application startup     
    mHomeViewController = [[HomeViewController alloc] initWithNibName:nil bundle:nil];      
    [tabBarController.view addSubview:mHomeViewController.view];     
    tabBarController.delegate = self;     
    [tabBarController addObserver:self forKeyPath:@"selectedViewController" options:NSKeyValueObservingOptionNew context:NULL];      
    // further initialization ... 
}  

// This method detects if user taps on one of the tabs and removes our "Home" view controller from the screen. 
- (BOOL) tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {     
    if (!mAllowSelectTab)     
    {         
        [mHomeViewController.view removeFromSuperview];         
        mAllowSelectTab = YES;     
    }      
    return YES; 
}  

// Here we detect if UITabBarController wants to select one of the tabs and set back to unselected. 
- (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.

0

Source: https://habr.com/ru/post/1769947/


All Articles