Ben*_*oit 8 cocoa objective-c tvos
有没有人知道如何通过单击tvOS上的"菜单"按钮来启用已被解除的UIAlertViewController?
Apple TV 4上的"设置"应用程序具有该行为,但在我的应用程序中默认不起作用.我使用以下代码创建用户可以执行的操作,但是希望他不要选择任何内容并按遥控器上的"菜单"按钮返回.
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Alert"
message:@"Please make a choice"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* action1 = [UIAlertAction actionWithTitle:@"Option 1" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {}];
[alert addAction:action1];
UIAlertAction* action2 = [UIAlertAction actionWithTitle:@"Option 2" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {}];
[alert addAction:action2];
[self presentViewController:alert animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
提前致谢.
Ben*_*oit 11
@ion:你的回答让我找到了正确的答案.
您确实需要添加一个样式为UIAlertActionStyleCancel的动作,以使菜单按钮按预期工作并退出UIAlertViewController.要从选项中隐藏此取消操作(无按钮,如在"设置"应用程序中),只需将其标题和处理程序设置为nil:
[alert addAction:[UIAlertAction actionWithTitle:nil style:UIAlertActionStyleCancel handler:nil]];
Run Code Online (Sandbox Code Playgroud)