在 iOS 4 中,只有点击按钮两次,UIActionSheet 才会起作用

发布于 2024-12-27 23:44:52 字数 788 浏览 1 评论 0原文

我有一个使用以下代码创建的 UIActionSheet

 UIActionSheet *popupQuery2 = [[UIActionSheet alloc] initWithTitle:@"Choose" 
                                                          delegate:nil 
                                                 cancelButtonTitle:@"Cancel" 
                                            destructiveButtonTitle:@"Accept Friendship" 
                                                 otherButtonTitles:@"Do not accept friendship",@"Check profile", nil];
popupQuery2.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[popupQuery2 setDelegate:self];
popupQuery2.tag=3;
[popupQuery2 showInView:self.view.superview];
[popupQuery2 release];

该代码在 iOS 5.0 上运行良好。问题出在4.0中。我必须点击 UIActionSheet 的按钮两次才能将其关闭!以前有人遇到过这个问题吗?

I have a UIActionSheet which I create with the following code.

 UIActionSheet *popupQuery2 = [[UIActionSheet alloc] initWithTitle:@"Choose" 
                                                          delegate:nil 
                                                 cancelButtonTitle:@"Cancel" 
                                            destructiveButtonTitle:@"Accept Friendship" 
                                                 otherButtonTitles:@"Do not accept friendship",@"Check profile", nil];
popupQuery2.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[popupQuery2 setDelegate:self];
popupQuery2.tag=3;
[popupQuery2 showInView:self.view.superview];
[popupQuery2 release];

The code is working on iOS 5.0 fine. The issue is in 4.0. I have to tap twice on the buttons of the UIActionSheet to dismiss it! Anyone got this issue before?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

千里故人稀 2025-01-03 23:44:52

谢谢大家的帮助,但问题是 ibaction 在 ios4 中被调用了两次!所以我在 stackoverflow 中搜索,发现了这个

if(sender.state != UIGestureRecognizerStateRecognized)
返回;

我已将上面的代码放入我的 ibaction 中并且它有效!

再次感谢您,我真的很感谢您的帮助!希望这对其他人有帮助,因为我已经研究了几个小时。

Thank you all for your help but the problem was that the ibaction was called two times in ios4! So i searched in stackoverflow and i have found this

if(sender.state != UIGestureRecognizerStateRecognized)
return;

I have putted the above code in my ibaction and it worked!!!

Thank you again i really appreciate your help! Hope this helps someone else because i have been looking into it for hours.

一笔一画续写前缘 2025-01-03 23:44:52

我在 iOS 8 中遇到类似的问题,使用带有 UIAlertControllerStyleActionSheet 样式的 UIAlertController 。虽然 Stefanosn 自己的答案解决了他的问题,但对我来说却并非如此。

我的问题是,操作表(任何按钮上)的第一次点击被忽略。

事实证明,这与我的文本字段的键盘干扰触摸有关。

解决方法是先关闭键盘,然后显示操作表。

[textfield resignFirstResponder];
[self presentViewController:alert animated:YES completion:nil];

I have similar problem in iOS 8, using UIAlertController with style UIAlertControllerStyleActionSheet. While the stefanosn's own answer solve for him, it is not the case for me.

My problem is that the first tap on the action sheet (on any button) is ignored.

Turned out it got to do with my text field's keyboard interfering with the touches.

The fix is to dismiss the keyboard first, then present the action sheet.

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