UIActionSheet不显示在iOS 8中

我可以在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]; 

UIActionSheet在iOS 8中已弃用。

在这里输入图像说明

要在iOS 8中创build和pipe理操作表,您应该使用UIAlertController和UIAlertControllerStyleActionSheet的preferredStyle。

参考这个例子 。

 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]; 

这显然是iOS 8的回归。我已经提交了rdar,请也这样做。

同时,你可以用一个类或者一个子类来修复它,在那里你检查视图是否是一个窗口,如果是的话,那么抓取该窗口上的rootViewController的视图,并使用它。 它会这样工作。

当iOS 8发布时,我遇到了问题。 你提出的观点可能是一个问题。你能以实际的视angular而不是窗口来展示它吗? 我会先在那里做实验,最坏的情况是将展示方法包装在iOS 7和8的特定项目中。我开始使用PSTAlertController来pipe理我的警报和操作表。 它支持UIAlertView,UIActionSheet和U​​IAlertController。 它会理清哪一个使用,以及让你访问阻止你的button的行动,同时还支持iOS 7和8。值得一看。

如果其他人看到这个问题,问题实际上是由iOS 8和9在屏幕键盘后面显示你的操作表引起的,所以你实际上看不到它。 你只是看到屏幕的其余部分变暗。 天才。

简单的解决scheme是在显示您的UIActionSheet之前添加一行代码:

 [self.view endEditing:true]; 

这消除了屏幕键盘,使您的美丽的行动表再次可见。