iOS 8 iPad只有动作表的bug

Ham*_*alp 1 xcode uiactionsheet ios

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

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];
Run Code Online (Sandbox Code Playgroud)

Gre*_*reg 6

试试这个:

[actionSheet showInView:[UIApplication sharedApplication].keyWindow.rootViewController.view];
Run Code Online (Sandbox Code Playgroud)

看起来你不能再UIWindow直接在s 上显示动作表了,你必须将它们呈现在由视图控制器管理的实际视图上,因此根视图控制器的视图非常适合这一点.

我认为这与UIActionSheet被弃用的事实关系不大(UIAlertController如果你需要支持iOS 7,你不能只是神奇地切换到它),而更多地与他们在底层实现中处理它们的表示方式有关 -我猜它现在依赖于视图,表单中有一个视图控制器,这对于Windows来说是不正确的.

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