App Delegate giving warning: 'id <UIApplicationDelegate>' does not conform to the 'UIAlertViewDelegate' protocol
I'm currently using a UIAlertView at startup in my app with the UIAlertViewDelegate. It all works fine. The only problem is, I get the warning "type 'id ' does not conform to the 'UIAlertViewDelegate' 开发者_StackOverflow社区protocol" every time I reference the App Delegate, giving me about 32 warnings.
Can anyone shed some light on why I'm getting this warning and how I can satisfy it?
Thanks in advance!
I assuming your app delegate is your alert view delegate?
If so, you need to tell the compiler that in the declaration of the app delegate. Like so:
@interface SomeAppDelegate : NSObject <UIApplicationDelegate, UIAlertViewDelegate> {
}
// ... rest of interface
@end
And then you also need to implement the required methods.
EDIT: Thinking about it further, I think probably you're missing a cast when you reference the app delegate. So you have something like this:
MyAppDelegate* appDelegate = [[UIApplication sharedApplication] delegate];
// what you want is:
MyAppDelegate* appDelegate = (MyAppDelegate*)[[UIApplication sharedApplication] delegate];
It might not exist on the main thread, try
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"My Title"
message:@"My message"
delegate:self cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:NO];
精彩评论