【问题标题】:UIAlertController dismiss on tvOS with menu buttonUIAlertController 在 tvOS 上关闭菜单按钮
【发布时间】:2016-02-27 12:42:55
【问题描述】:

有谁知道如何通过单击 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];

提前致谢。

【问题讨论】:

    标签: objective-c cocoa tvos


    【解决方案1】:

    您必须在样式为 UIAlertActionStyleCancel 的控制器中至少有一个 UIAlertAction 才能使菜单按钮按预期工作。

    【讨论】:

      【解决方案2】:

      @ion:你的回答让我找到了正确的答案。

      您确实需要添加一个样式为 UIAlertActionStyleCancel 的操作,以使菜单按钮按预期工作并退出 UIAlertViewController。 要从选项中隐藏此取消操作(无按钮,如设置应用程序中),只需将其 Title 和 Handler 设置为 nil:

      [alert addAction:[UIAlertAction actionWithTitle:nil style:UIAlertActionStyleCancel handler:nil]];
      

      【讨论】:

      • 我也在尝试做同样的事情并使用了上面的代码,但是现在菜单按钮不仅取消了我的警报控制器,而且还关闭了它下面的视图控制器。有什么建议吗?
      【解决方案3】:

      在斯威夫特中:

      alertController.addAction(UIAlertAction(title: nil, style: .cancel, handler: nil))
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-03-12
        • 2023-04-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多