App Delegate发出警告:'id <uiapplicationdelegate>'不符合'UIAlertViewDelegate'协议</uiapplicationdelegate>

时间:2010-10-24 02:22:14

标签: iphone ios4 uialertview uiapplicationdelegate

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

任何人都可以解释为什么我会收到这个警告以及我如何满足它?

提前致谢!

2 个答案:

答案 0 :(得分:6)

我假设你的app delegate是你的警报视图委托?

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

@interface SomeAppDelegate : NSObject <UIApplicationDelegate, UIAlertViewDelegate> {

}

// ... rest of interface

@end

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

编辑:进一步思考,我想你可能在引用应用代表时错过演员。所以你有这样的事情:

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

// what you want is:

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

答案 1 :(得分:0)

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

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