委托方法“clickedButtonAtIndex:”不叫 [英] The delegate method "clickedButtonAtIndex:" is not called

查看:133
本文介绍了委托方法“clickedButtonAtIndex:”不叫的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码创建了一个包含两个按钮的警报视图:

I have created an alert view with two buttons using the following code:

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

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

I want to run some code when one of the buttons is clicked. In order to do so, I have added the following method to the delegate.m file:

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

但是当我按下任一按钮时,不会调用此方法!
有人可以告诉我原因吗?

But this method is not called when I press either of the buttons! Can someone tell me why?

提前致谢,

Sagiftw

推荐答案

delegate:nil

如果您指定不会有委托,警报视图如何关联委托?用

how will the alert view associate a delegate if you specified there will be no delegates? Replace that part with

delegate:self

而不是。

这篇关于委托方法“clickedButtonAtIndex:”不叫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆