我在MyapplicationAppDelegate.m文件中用2个按钮“取消”和“确定”调用UIAlert,调用警报,但点击“取消”或“确定”按钮
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
方法未被调用。
我在MyapplicationAppDelegate.h文件中添加了UIAlertViewDelegate,如下所示
#import UIKit/UIKit.h
@interface MyapplicationAppDelegate: NSObject UIApplicationDelegate,UIAlertViewDelegate
{
..
}
我想知道还需要什么。
答案 0 :(得分:5)
我不确定在发布问题时是否是您的拼写错误,但您应该在< ..,..>
中调用该委托@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设置了委托
答案 1 :(得分:2)
对我来说,
#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];
诀窍!
现在它在AppDelegate文件中进入-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
而不添加,
@interface MyapplicationAppDelegate: NSObject <UIApplicationDelegate,UIAlertViewDelegate> { .. }