iOS 8 iPad只有动作表的bug [英] iOS 8 iPad only bug with action sheets

查看:119
本文介绍了iOS 8 iPad只有动作表的bug的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在运行iOS 8的iPhone上,下面的代码会弹出一个操作表。但是,在运行iOS 8的iPad上,下面的代码不会导致弹出操作表,而是没有任何反应。

On an iPhone running iOS 8, the code below causes an action sheet to pop up. However, on an iPad running iOS 8 the code below does not cause an action sheet to pop up and instead nothing happens.

NSUserDefaults *defauj = [NSUserDefaults standardUserDefaults];
NSArray *cod = [defauj objectForKey:@"customlistofstuff"];

UIActionSheet* actionSheet = [[UIActionSheet alloc] init];
actionSheet.delegate = self;
for(int i=0;i<[cod count];i++)
{
    [actionSheet addButtonWithTitle:[cod objectAtIndex:i]];
}
actionSheet.cancelButtonIndex = [actionSheet addButtonWithTitle:@"None"];
[actionSheet showInView:[UIApplication sharedApplication].keyWindow];


推荐答案

试试这个:

[actionSheet showInView:[UIApplication sharedApplication].keyWindow.rootViewController.view];

看起来您无法在 UIWindow s,你必须将它们呈现在由视图控制器管理的实际视图上,因此根视图控制器的视图非常适用于此。

It looks like you can't present action sheets on UIWindows directly anymore, you have to present them on an actual view that is managed by a view controller, so the root view controller's view is perfect for this.

我认为这与 UIActionSheet 被弃用的事实关系不大(你不能只是神奇地切换到 UIAlertController 如果你需要支持iOS 7),还有更多关于它们在底层实现中处理它们的方式的方式 - 我猜它现在依赖于在具有视图控制器时呈现工作表的视图对于Windows来说不是这样。

I think this has less to do with the fact that UIActionSheet is deprecated (and you can't just magically switch to UIAlertController just yet if you need to support iOS 7), and more to do with the way their presentation is handled in the underlying implementation — I'm guessing it now relies on the view the sheet is presented in having a view controller, which is not true for windows.

编辑:如果你有一个视图控制器以模态方式呈现在根视图控制器的顶部,这显然赢了因为根视图控制器的视图不再可见而工作。您需要在当前可见的视图中显示工作表,例如当前视图控制器的视图( self.view )。

EDIT: If you have a view controller presented modally over the top of the root view controller, this obviously won't work as the root view controller's view is no longer visible. You'll need to present the sheet in a view that is currently visible, e.g. the view of the current view controller (self.view).

这篇关于iOS 8 iPad只有动作表的bug的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆