开发者

AppDelegate may not respond to 'delegate'

I'm getting the error 'MillersAppAppDelegate' may not respond to 'delegate'. I'm still learning all of this but don't understand entirely because I've read开发者_开发问答 that this generally happens when a method isn't declared in the header file. I'm using XCode 4. Here's the part of the code I'm looking at:

#import <UIKit/UIKit.h>

@interface MainViewController : UIViewController {    
}
-(IBAction) contactButtonClick:(id)sender;

@end

And here's the .m file:

#import "MainViewController.h"
#import "MillersAppAppDelegate.h"
#import "ContactViewController.h"

@implementation MainViewController

-(IBAction) contactButtonClick:(id)sender{
    MillersAppAppDelegate *delegate = [(MillersAppAppDelegate *)[UIApplication     sharedApplication] delegate]; <---this line gets the warning "'MillersAppAppDelegate' may not respond to 'delegate'"
    ContactViewController *contactView = [[ContactViewController     alloc]initWithNibName:@"ContactViewController" bundle:nil];
    [delegate switchViews:self.view toView:contactView.view];
}

The program runs fine but I've got several other actions that come up with the same warnings (all dealing with view switches). Thanks for the help, I'm sure it's an easy answer but I'm still a beginner. This may also be an issue between XCode3 and XCode 4?


Try

(MillersAppAppDelegate *)[[UIApplication sharedApplication] delegate];

instead :)

You want to cast the [[UIApplication sharedApplication] delegate] to MillersAppAppDelegate.

You accidentally casted sharedApplication itself to MillersAppAppDelegate

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜