iphone - 未调用委托(delegate)方法 "clickedButtonAtIndex:"

标签 iphone objective-c uialertview

我使用以下代码创建了一个带有两个按钮的警报 View :

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle: title 
message: msg delegate:nil cancelButtonTitle:@"Replay" otherButtonTitles:@"Highscore", nil];
[alertView show];

我想在单击其中一个按钮时运行一些代码。 为此,我在 delegate.m 文件中添加了以下方法:

 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
 if (buttonIndex==0) //Run some code 
 else //Other code
 }

但是当我按下任何一个按钮时,这个方法都没有被调用! 谁能告诉我为什么?

提前致谢

迅捷

最佳答案

delegate:nil

如果您指定没有委托(delegate),警报 View 将如何关联委托(delegate)?将该部分替换为

delegate:self

相反。

关于iphone - 未调用委托(delegate)方法 "clickedButtonAtIndex:",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2537993/

相关文章:

ios - UIAlertView 的标题被传递到不同屏幕上的 UITextField

iphone - 边界检测纸张opencv

objective-c - 如何限制 iOS 中 NSInteger 的最大数量?

objective-c - 无法触发 UITableView 委托(delegate)方法 "DidSelectRowAtIndexPath"

iphone - 以不同的方法关闭警报 View

ios - 努力将多个文本字段添加到 alertview

iphone - 如何在 iphone sdk 运行时对 TableView 中的行重新排序

ios - 在相机打开的情况下使用 Spotify/背景音乐

iphone - linkshare.com 能否用于跟踪 Apple 应用商店中的免费应用转化情况?

ios - 为什么@try 不起作用