App Delegate giving warning: 'id <UIApplicationDelegate>' does not conform to the 'UIAlertViewDelegate' protocol

StackOverflow https://stackoverflow.com/questions/4006921

Question

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' 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!

Was it helpful?

Solution

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];

OTHER TIPS

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];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top