作者iasm (魔术研究员)
看板MacDev
标题Re: [问题] UIAlertview为何按钮无法触发事件?
时间Wed Sep 15 13:05:28 2010
我在另一个讨论区有post文章
http://tinyurl.com/27q96fd
也有上传sample code,我看了很多人遇到相同的问题是因为
没有在UIAlertView产生instance时设定delegate:self,但是我有
范例如下
- (IBAction)displayAlertView
{
UIAlertView *view = [[UIAlertView alloc]
initWithTitle"Alert View Demo"
message"请选择"
delegate:self
cancelButtonTitle"取消"
otherButtonTitles"储存",@"载入",nil];
[view show];
[view release];
}
有兴趣的朋友请到如上连结下载sample code跑看看
理论上应该是可以在按任一个UIAlertView上的按钮时,触发NSLog讯息
除非这里的delegate不是nil或self
而且我的范例是某书上的sample code,我一行未改直接build就发现这个问题了...orz
※ 引述《iasm (魔术研究员)》之铭言:
: 请教各位
: 我完全照着如下网址练习一个UIAlertview的范例
: 可是
: 当我在alertview的视窗中按下按钮
: 范例中判断用户究竟按下了那一个按钮的method完全没有触发
: 想请教大家为什麽
: 我也有用在相对应的 Class 加上 UIAlertViewDelegate 的 protocol
: 而且我也看了好几个youtube教学,有些人甚至没加UIAlertViewDelegate
: 想请教大家,我到底少作了什麽步骤
: http://pro.ctlok.com/2010/08/iphone-ipad-uialertview.html
: https://www.youtube.com/watch?v=TaxZWtScaS0
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.96.39.165