views:

31

answers:

1

Hello everyone,

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!

+1  A: 

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];
Firoze Lafeer
Sorry, I should have added the code snippet but this is what I already have and it's still creating the warnings. That's why I found it so odd.
DysonApps
And an example of where you are referencing the app delegate? Actual code is really helpful when you're asking questions. :) Perhaps you aren't casting the result from [[UIApplication sharedApplication] delegate]
Firoze Lafeer
Second thought, I think the missing cast is most likely the issue. I edited my answer above.
Firoze Lafeer
The code in your edit worked. I was using the first example. I have a good idea already but could you explain why I needed a cast in this scenario? I'm curious and for others stumbling upon this page...
DysonApps
Yeah, like most things it's a lot clearer to me this morning than it was last night. :) So 'appDelegate' is declared as MyAppDelegate*, which implies that is must satisfy <UIApplicationDelegate> AND <UIAlertViewDelegate>. But the property 'delegate' in UIApplication is declared as type id<UIApplicationDelegate>. So the compiler is just warning you that this id<UIApplicationDelegate> type doesn't satisfy <UIAlertViewDelegate>. The cast says, no, the delegate is actually a MyAppDelegate*.
Firoze Lafeer