【问题标题】:iOS 8 today widget - UIAlertViewiOS 8 今日小部件 - UIAlertView
【发布时间】:2014-06-09 11:54:34
【问题描述】:

是否可以将 UIAlertView 之类的内容添加到今天的小部件中?我向小部件添加了一个 IBAction 和一个 UIAlertView,但什么也没发生。

有没有可能制作一个更大的小部件?我在 Size-Inspector 中更改了高度,但它根本不起作用。

【问题讨论】:

  • UIAlertViews 和 UIActionSheets 已被弃用,您现在可以使用 UIAlertController
  • 你有例子吗?它不会工作:(

标签: ios objective-c uialertview ios-app-extension today-extension


【解决方案1】:

简短的回答是否定的,您不能在今天的小部件中显示警报。 UIAlertController 以模态方式呈现,您的小部件无法访问整个屏幕。它有大约 3/4 的最大屏幕高度可以显示。

【讨论】:

    【解决方案2】:

    这里有一些基本代码可以在 swift 中执行此操作(用于未来的项目):

    let alertController = UIAlertController(title: "title", message: "message", preferredStyle: .Alert)
    self.presentViewController(alertController, animated: true, completion: nil)
    

    【讨论】:

    • UIAlertControllers 全屏显示,不能在今天的小部件中使用
    【解决方案3】:

    iOS8上需要使用UIAlertController,参考是here

    例如:

    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"AlertView" message:@"I am an AlertView" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
                                                          handler:^(UIAlertAction * action) {
                                                              [alert dismissViewControllerAnimated:YES completion:nil];
                                                          }];
    [alert addAction:defaultAction];
    [self presentViewController:alert animated:YES completion:nil];
    

    【讨论】:

    • 实际上,如果您尝试在 Today App Extension Widget 中执行此操作,您会在运行时得到:2014-08-25 16:42:21.994 LauncherWidget[76137:2316933] *** 终止应用程序到期未捕获的异常 'NSInternalInconsistencyException',原因:'功能在 com.apple.widget-extension 类型的扩展中不可用'
    • 是的,很抱歉这在测试版中有效,但它不再有效
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多