I have a simple app with a tab bar which based upon user input disables one or more of the bar items. I understand I need to use a UITabBarDelegate which I have tried to use. However when I call the delegate method I get an uncaught exception error [NSObject doesNotRecognizeSelector]. I am not sure I am doing this all right or that I haven't missed something. Any suggestions.
What I have now is the following:
WMViewController.h
#import <UIKit/UIKit.h>
#define kHundreds 0
@interface WMViewController : UIViewController <UITabBarDelegate, UIPickerViewDelegate, UIPickerViewDataSource>{
}
@end
WMViewController.m
#import "WMViewController.h"
#import "MLDTabBarControllerAppDelegate.h"
@implementation WMViewController
- (IBAction)finishWizard{
MLDTabBarControllerAppDelegate *appDelegate = (MLDTabBarControllerAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate setAvailabilityTabIndex:0 Enable:TRUE];
}
MLDTabBarControllerAppDelegate.h
#import <Foundation/Foundation.h>
@interface MLDTabBarControllerAppDelegate : NSObject <UITabBarDelegate>{
}
- (void) setAvailabilityTabIndex: (NSInteger) index Enable: (BOOL) enable;
@end
MLDTabBarControllerAppDelegate.m
#import "MLDTabBarControllerApplicationDelegate.h"
#import "MyListDietAppDelegate.h"
@implementation MLDTabBarControllerAppDelegate
- (void) setAvailabilityTabIndex: (NSInteger) index Enable: (BOOL) enable
{
UITabBarController *controller = (UITabBarController *)[[[MyOrganizerAppDelegate getTabBarController] viewControllers ] objectAtIndex:index];
[[controller tabBarItem] setEnabled:enable];
}
@end
I get what appear to be a good controller object but crash on the [[controller tabBarItem]setEnabled:enable];
What am I missing...
Any suggestions
Thanks,
// Disable
UITabBarController.tabbar.userInteractionEnabled = NO;
// Enable
UITabBarController.tabbar.userInteractionEnabled = YES;
You need to implement the UITabBarControllerDelegate, in particular
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
and return NO for those viewControllers that should be disabled.
self.tabBarController?.tabBar.userInteractionEnabled = false
will do it in swift
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With