为什么解雇WithClickedButtonIndex不调用clickedButtonAtIndex?

发布于 2024-10-08 07:20:48 字数 566 浏览 3 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

北方的巷 2024-10-15 07:20:48

因为这是一个老问题,你现在可能已经弄清楚了,但我对此感到非常沮丧,并且无法从 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 is alertView:didDismissWithButtonIndex, not alertView: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.

装迷糊 2024-10-15 07:20:48

当用户实际单击按钮时,会调用 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 a dismissWithClickedbuttonIndex method is called, then did DismissWithButtonIndex is called.

放低过去 2024-10-15 07:20:48

我不确定我是否完全理解您的问题,但这是我的尝试:

首先,您需要从示例中删除 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 the UITextFieldDelegate. 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?

韬韬不绝 2024-10-15 07:20:48

我对 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文