【问题标题】:UIActionSheet will not act until buttons are tapped twice in iOS 4UIActionSheet 直到按钮在 iOS 4 中被点击两次才会起作用
【发布时间】:2012-02-12 13:36:46
【问题描述】:

我有一个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 的按钮上点击两次才能将其关闭!有人遇到过这个问题吗?

【问题讨论】:

  • 你为什么要在前面两行创建工作表时使用[popupQuery2 setDelegate:self] 而不是设置委托?
  • 我尝试过同样的事情......还有其他想法吗?

标签: objective-c ios cocoa-touch ios4 uiactionsheet


【解决方案1】:

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

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

我已将上述代码放入我的 ibaction 中,它成功了!!!

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

【讨论】:

    【解决方案2】:

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

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

    原来这与我的文本字段的键盘干扰触摸有关。

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-01
      • 1970-01-01
      • 2013-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-02
      • 1970-01-01
      相关资源
      最近更新 更多