Reputation: 8820
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
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
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
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