有人可以解释 UIAlertView
的委托(delegate)是如何工作的吗?它是自动调用还是我必须调用它?例如:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
最佳答案
假设您在代表是“自己”的地方显示了一个警报
- (void)showAlert {
UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"My Alert"
message:@"Do you want to continue?"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"No", @"Yes", nil];
[myAlert show];
[myAlert release];
}
为了使以下内容在您的 .m 文件中起作用:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
您的 .h 文件需要在实现语句中引用 UIAlertViewDelegate,如下所示:
@interface myViewController : UIViewController <UIAlertViewDelegate> {
}
这是允许您的 .m 文件响应 UIAlertViewDelegate 方法调用的原因。
关于iphone - UIAlertView 代表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3826659/