views:

233

answers:

1

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,

A: 

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.

adam