如何在程序中编程隐藏UIAlertView?

37

有没有一种方法可以以编程方式隐藏UIAlertView?实际上,我已经在UIAlertView中添加了一个UITextField,并且当用户按下键盘的返回键时,我想执行与“Ok”按钮按下相同的操作。

有没有办法以编程方式隐藏UIAlertView?实际上,我已经在UIAlertView中添加了一个UITextField,并且当用户按下键盘的返回键时,我想要执行与“Ok”按钮相同的操作。
1个回答

81

调用

[theAlertView dismissWithClickedButtonIndex:0 animated:YES];

当你处理回车键时。


1
谢谢。如果你想要更灵活一点,你也可以这样说:[theAlertView dismissWithClickedButtonIndex: theAlertView.cancelButtonIndex animated:YES]; 或者 [theAlertView dismissWithClickedButtonIndex: theAlertView.firstOtherButtonIndex animated:YES]; 来点击第一个非取消按钮。 - palme

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接