开发者

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

开发者 https://www.devze.com 2023-01-21 07:28 出处:网络
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 \'UIAlertViewDele

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

精彩评论

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

关注公众号