Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to conform to UITabBarControllerDelegate

I have a tabbar based application and do the following to get a reference to the application delegate:

MyAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];

Which then gives this warning:

warning: type 'id <UIApplicationDelegate>' does not conform to the 'UITabBarControllerDelegate' 

My application delegate header looks like this:

#import <UIKit/UIKit.h>

@interface MyAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate>     {
UIWindow *window;
UITabBarController *tabBarController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;

@end

The only methods in the .m file are applicationDidFinishLaunching and dealloc. What else do I need to conform to the protocol?

like image 603
4thSpace Avatar asked Feb 06 '10 20:02

4thSpace


1 Answers

It's a static warning. It means that the return type of [[UIApplication sharedApplication] delegate] does not conform to the tab bar delegate protocol, which is true.

Cast the value returned from [[UIApplication sharedApplication] delegate] to get rid of the warning:

MyAppDelegate *appDelegate = (MyAppDelegate*)[[UIApplication sharedApplication] delegate];
like image 124
Darren Avatar answered Oct 04 '22 01:10

Darren