iOS 8 中 UIActionSheet 不显示

4

我可以在iOS 7中显示操作表(actionSheet),但无法在iOS 8环境中显示。有没有办法进行跟踪追踪?

  UIActionSheet *_actionSheet = [[UIActionSheet alloc] initWithTitle:@"Account"
                                                               delegate:self 
                                                      cancelButtonTitle:@"Close" 
                                                 destructiveButtonTitle:@"Log Out" 
                                                      otherButtonTitles:@"View Account", nil];

    [_actionSheet showInView:appDel.window];

1
这是因为在iOS8中,UIActionSheets已经被弃用,取而代之的是UIAlertController。请阅读https://developer.apple.com/Library/ios/documentation/UIKit/Reference/UIAlertController_class/index.html。 - Popeye
2
@Popeye,“deprecated”并不意味着“被淘汰”,而是“请避免使用”。尽管如此,它仍然可以工作。 - Nas Banov
在我的iPhone应用程序中,不,它不再起作用了。随着iOS 9的到来,我的UIActionSheet现在只是使整个屏幕变暗,没有弹出菜单会出现。我修复的详细信息在这里:https://dev59.com/hY_ea4cB1Zd3GeqPP46I#35316029(叹气...) - Mike Gledhill
5个回答

3

UIActionSheet在iOS 8中已经被弃用。

enter image description here

在iOS 8中创建和管理操作表,您应该使用preferredStyle为UIAlertControllerStyleActionSheet的UIAlertController。

请参考这个示例


1
我也参考了这个页面,但是我得到了“您必须提供sourceView和sourceRect或barButtonItem。如果在呈现警报控制器时不知道此信息,则可以在UIPopoverPresentationControllerDelegate方法-prepareForPopoverPresentation中提供它。” 我参考了其他页面,但我卡在了按钮部分。https://dev59.com/LGAf5IYBdhLWcg3w2Fl6 - shoujo_sm

1
UIAlertController * alert=   [UIAlertController
                             alertControllerWithTitle:@"Info"
                             message:@"You are using UIAlertController"
                             preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction* ok = [UIAlertAction
                    actionWithTitle:@"OK"
                    style:UIAlertActionStyleDefault
                    handler:^(UIAlertAction * action)
                    {
                        [alert dismissViewControllerAnimated:YES completion:nil];

                    }];
UIAlertAction* cancel = [UIAlertAction
                        actionWithTitle:@"Cancel"
                       style:UIAlertActionStyleDefault
                       handler:^(UIAlertAction * action)
                       {
                           [alert dismissViewControllerAnimated:YES completion:nil];

                       }];

 [alert addAction:ok];
 [alert addAction:cancel];

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

0
如果有其他人遇到这个问题,实际上是由于iOS 8和9将您的操作表显示在屏幕键盘后面,因此您实际上无法看到它。您只能看到屏幕的其余部分变暗。太聪明了。
简单的解决方案是在显示您的UIActionSheet之前添加一行代码:
[self.view endEditing:true];

这将关闭屏幕键盘,使您美丽的操作表重新可见。


0

这显然是iOS 8中的一个回归问题。我已经提交了一个rdar,请您也这样做。

同时,您可以通过使用分类或子类来修复它,在其中检查视图是否为窗口,如果是,则在该窗口上获取rootViewController的视图并使用它代替。这样就能解决问题了。


0

当iOS 8发布时,我遇到了操作表的问题。这可能是与您正在呈现的视图有关的问题。您能否在实际视图中显示它,而不是窗口中?我建议您首先在那里进行实验,如果最坏情况下,可以将show方法封装成适用于iOS 7和8的特定内容。我开始使用PSTAlertController来管理我的警报和操作表。它支持UIAlertView、UIActionSheet和UIAlertController。它将解决要使用哪一个,并为您的按钮提供访问块操作,同时仍支持iOS 7和8。值得一看。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接