为什么解雇WithClickedButtonIndex不调用clickedButtonAtIndex?
http://iphonedevelopment.blogspot.com/2009/02/alert-view-with- prompt.html
我正在使用该代码让我的 iPhone 应用程序显示一个包含 UITextField 和匹配的取消和确定按钮的警报视图。
用户可以输入文本,点击“取消”或“确定”...,我会看到用户输入的文本...使用 clickedButtonAtIndex 方法中的代码。
除了一件事之外,一切都有效:用户可能会在键盘上点击“完成”,而不是“确定”。 我使用 dismissWithClickedButtonIndex 来模拟“确定”单击...但 clickedButtonAtIndex 永远不会被调用。
missWithClickedButtonIndex 不应该也调用 clickedButtonAtIndex 吗?
我试图在点击“取消”、“确定”甚至“完成”时调用 clickedButtonAtIndex 。
http://iphonedevelopment.blogspot.com/2009/02/alert-view-with-prompt.html
I'm using that code to get my iPhone app to display an alertView with an included UITextField and matching CANCEL and OK buttons.
The user can enter text, hit CANCEL or OK... and I see the text the user entered... using my code inside the clickedButtonAtIndex method.
It all works except for 1 thing: Instead of OK, the user might hit DONE on the keyboard.
I'm using dismissWithClickedButtonIndex to simulate an OK click... but then clickedButtonAtIndex never gets called.
Shouldn't dismissWithClickedButtonIndex also call clickedButtonAtIndex?
I'm trying to get clickedButtonAtIndex to get called if CANCEL, or OK, or even DONE is hit.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
因为这是一个老问题,你现在可能已经弄清楚了,但我对此感到非常沮丧,并且无法从 Google 找到任何帮助,因此对于将来遇到此问题的任何人:当你致电
missWithClickedbuttonIndex
,被调用的方法是alertView:didDismissWithButtonIndex
,而不是alertView:clickedButtonAtIndex
。它的行为方式完全相同,我不明白为什么它们是两个不同的方法来执行看似相同的操作,但事实就是如此。Since this is an old question you've probably figured it out by now, but I was incredibly frustrated with this and couldn't find any help from Google, so for anyone who comes across this in the future: when you call
dismissWithClickedbuttonIndex
, the method that gets called isalertView:didDismissWithButtonIndex
, notalertView:clickedButtonAtIndex
. It behaves exactly the same way, and I can't figure out why they'd be two separate methods for what seems to be the same action, but there it is.当用户实际单击按钮时,会调用
clickedButtonAtIndex
。单击该按钮可能会也可能不会消除警报。标准的“确定”/“取消”按钮具有在单击时消除警报的效果。如果单击转换为关闭或调用了dismissWithClickedbuttonIndex
方法,则调用DismissWithButtonIndex
。clickedButtonAtIndex
is called when user actually clicks the button. Clicking the button may or may not dismiss the alert. the standard OK/Cancel buttons have the effect of dismissing the alert on click. If a click translates to dismiss or adismissWithClickedbuttonIndex
method is called, then didDismissWithButtonIndex
is called.我不确定我是否完全理解您的问题,但这是我的尝试:
首先,您需要从示例中删除
if (buttonIndex != [alertView cancelButtonIndex])
。这应该适用于“确定”和“取消”按钮。要识别键盘的 DONE 键,请使用
UITextFieldDelegate
的- (BOOL)textFieldShouldReturn:(UITextField *)textField
。这里你可以调用[textField resignFirstResponder]
来关闭键盘。另外,您在
clickedButtonAtIndex
中做什么?您不能创建自己的方法并在需要时调用它吗?I'm not sure whether I fully understand your question, but here is my try:
Firstly, you need to remove the
if (buttonIndex != [alertView cancelButtonIndex])
from the example. This should work for the OK and CANCEL buttons.To recognize the DONE key of the keyboard, use
- (BOOL)textFieldShouldReturn:(UITextField *)textField
of theUITextFieldDelegate
. Here you could call[textField resignFirstResponder]
to dismiss the keyboard.Also, what to you do in
clickedButtonAtIndex
? Couldn't you create your own method and the call it when you need it?我对 UIAlertView(Blocks) 类别有同样的问题
UIAlertView-Blocks
我的解决方案:UIAlertView(Blocks) -> MYAlertView : UIAlertView
有时方法:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
被调用。有时也没有叫。所以...我尝试在许多来源中找到解决方案。然后我用完全相同的代码创建了 UIAlertView 的子类。我的问题解决了。事实上,使用起来有点困难。但不再有这种侵入性的错误。
I had the same problem with UIAlertView(Blocks) categoty
UIAlertView-Blocks
My solution:UIAlertView(Blocks) -> MYAlertView : UIAlertView
Sometimes method:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
called. Sometimes it didn't call.So... I tried to find solution in many sources. Then I'he created subclass of UIAlertView with absolutely same code. And my problem was solved. In fact it is little bit more difficult to use. But no more this intrusive bugs.