Madan Mohan
Madan Mohan

Reputation: 8820

How to disable the UITabBarController buttons in the Master View Controller in iOS?

When I tab through the UITabBarController buttons while loading the data, I get an exception. How can I get through this problem?

How can I disable the buttons until the data is loaded, to avoid the exception being caused?

Upvotes: 3

Views: 4029

Answers (3)

So Over It
So Over It

Reputation: 3698

Another way of approaching this would be conform to the <UITabBarControllerDelegate> protocol.

@interface SomeViewController : UIViewController <UITabBarControllerDelegate>
@property (nonatomic) BOOL tabbarShouldRespond;
//..
//..

then

@implementation SomeViewController
//..
// become the delegate for our UITabBarController - probably in viewDidLoad
self.tabBarController.delegate = self;
//..
// set our BOOL for whether the tab bar should respond to touches based on program logic
self.tabbarShouldRespond = NO;
//..
//..
#pragma mark <UITabBarControllerDelegate>
//Asks the delegate whether the specified view controller should be made active.
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
    if (self.tabbarShouldRespond) {
        return YES;
    } else {
        return NO;
    }
}

Apple Docs - UITabBarControllerDelegate Protocol Reference

Upvotes: 6

software evolved
software evolved

Reputation: 4352

Here's code to enable/disable all items in a tab bar.

+(void) setAllItemsInTabBar:(UITabBarController *)aTabBar toEnableState:(BOOL)enableState
{
    NSArray *tabItems = aTabBar.tabBar.items;
    for (UIBarItem *tabItem in tabItems) 
    {
        [tabItem setEnabled:enableState];
    }
}

Upvotes: 9

Eiko
Eiko

Reputation: 25632

You can disable and enable all of your UI with

[[UIApplication sharedApplication] beginIgnoringInteractionEvents];

[[UIApplication sharedApplication] endIgnoringInteractionEvents];

That being said, I recommend digging down and understanding why the app crashes, as you will want to solve the problem and not hide bugs.

One quick shot: Are you doing the loading on another thread? You may only update the UI from the main thread.

Upvotes: 6

Related Questions