appdelegate中的clickedButtonAtIndex不被调用

我使用MyApplicationAppDelegate.m文件中的两个button“取消”和“确定”来调用UIAlert,但只需点击“取消”或“确定”button

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 

方法不被调用。

我在下面的MyapplicationAppDelegate.h文件中添加了UIAlertViewDelegate

 #import UIKit/UIKit.h @interface MyapplicationAppDelegate: NSObject UIApplicationDelegate,UIAlertViewDelegate { .. } 

我想知道还有什么是必需的。

我不确定是否在发布问题时出现错字,但您应该在<..,..>内调用委托

 @interface MyapplicationAppDelegate: NSObject <UIApplicationDelegate,UIAlertViewDelegate> { .. } 

这里是UIAlertView的示例代码

 UIAlertView *myAlertView = [[UIAlertView alloc]initWithTitle:@""message:@"Your message goes here" delegate:self cancelButtonTitle:@"OK"otherButtonTitles:nil]; [myAlertView show]; [myAlertView release]; 

我不知道myAlertView.delgate = self是正确的方法,但我设置委托与initWithTitle

为了我,

 #define appDelegate ((AppDelegate*)[UIApplication sharedApplication].delegate) UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"Say Yes or NO?" delegate:appDelegate cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil]; alertView.tag = 1; [alertView show]; [alertView release]; 

做诡计!

现在进入-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex; 在AppDelegate文件中不添加,

 @interface MyapplicationAppDelegate: NSObject <UIApplicationDelegate,UIAlertViewDelegate> { .. }