Pages

July 6, 2013

Enable/Disable a Tab of UITabBarController

Simple but very helpful method that enables or disables a Tab from a UITabBar in Cocoa framework.


/** Enable or disable a tab from UITabBarController.

 @param tabBarController Container TabBar.
 @param enableState Boolean value that defines enable (true) or disable (false).
 @param index Index of the tab to be enabled or disabled.

 */
+ (void)tabBar:(UITabBarController *)tabBarController setEnable:(BOOL)enableState forItemAtIndex:(NSInteger)index {
    if (!tabBarController) { return; }
    if (index < [tabBarController.tabBar.items count]) {
        UIBarItem *item = [tabBarController.tabBar.items objectAtIndex:index];
        [item setEnabled:enableState];
    }
}



Download the ready-for-use source file (.m) of Enable/Disable a Tab of UITabBarController

No comments:

Post a Comment