Pat*_*cia 13 iphone uitextfield uialertview
http://iphonedevelopment.blogspot.com/2009/02/alert-view-with-prompt.html
我正在使用该代码让我的iPhone应用程序显示一个包含UITextField并匹配CANCEL和OK按钮的alertView.
用户可以输入文字,点击取消或确定......我看到用户输入的文本...使用clickedButtonAtIndex方法在我的代码.
这一切都有效,除了一件事:用户可能会在键盘上点击DONE而不是OK.我正在使用dismissWithClickedButtonIndex来模拟一个OK点击...但是clickedButtonAtIndex永远不会被调用.
不应该dismissWithClickedButtonIndex也调用clickedButtonAtIndex?
我试图让clickedButtonAtIndex被调用,如果CANCEL,OK,甚至DONE被击中.
jcs*_*nt0 37
由于这是一个老问题,你可能已经想通了现在,但我是这个令人难以置信的沮丧,无法找到谷歌的任何帮助,所以任何人谁在今后遇到这样的:当你打电话dismissWithClickedbuttonIndex的方法被召唤的是alertView:didDismissWithButtonIndex,不是alertView:clickedButtonAtIndex.它的行为方式完全相同,我无法弄清楚为什么它们是两个独立的方法,似乎是同一个动作,但它确实存在.
我不确定我是否完全理解你的问题,但这是我的尝试:
首先,您需要if (buttonIndex != [alertView cancelButtonIndex])从示例中删除 。这应该适用于“确定”和“取消”按钮。
要识别键盘上的 DONE 键,请- (BOOL)textFieldShouldReturn:(UITextField *)textField使用UITextFieldDelegate. 在这里你可以调用[textField resignFirstResponder]关闭键盘。
另外,你要做什么clickedButtonAtIndex?您不能创建自己的方法并在需要时调用它吗?