应用程序委托发出警告:“id”不符合“UIAlertViewDelegate”协议

发布于 2024-09-28 22:39:35 字数 199 浏览 2 评论 0原文

我目前在我的应用程序中启动时使用 UIAlertView 和 UIAlertViewDelegate。一切都很好。唯一的问题是,每次引用 App Delegate 时,我都会收到警告“type 'id '不符合 'UIAlertViewDelegate' 协议”,这给了我大约 32 个警告。

谁能解释一下我为什么收到此警告以及如何满足它?

提前致谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清旖 2024-10-05 22:39:35

我假设您的应用程序委托是您的警报视图委托?

如果是这样,您需要在应用程序委托的声明中告诉编译器。像这样:

@interface SomeAppDelegate : NSObject <UIApplicationDelegate, UIAlertViewDelegate> {

}

// ... rest of interface

@end

然后你还需要实现所需的方法。

编辑:进一步考虑一下,我认为当您引用应用程序委托时,您可能错过了演员表。所以你有这样的东西:

MyAppDelegate* appDelegate = [[UIApplication sharedApplication] delegate];

// what you want is:

MyAppDelegate* appDelegate = (MyAppDelegate*)[[UIApplication sharedApplication] delegate];

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];
权谋诡计 2024-10-05 22:39:35

它可能不存在于主线程上,请尝试

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"My Title"
                                                    message:@"My message"
                                                   delegate:self cancelButtonTitle:@"OK"
                                          otherButtonTitles:nil];
[alertView performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:NO];

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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文