【问题标题】:UIActionSheet vs UIAlertController - iPadUIActionSheet 与 UIAlertController - iPad
【发布时间】:2014-08-24 08:32:39
【问题描述】:

我们是否必须在 iOS8 中使用 UIAlertController 还是仍然可以使用 UIActionSheet?

我不希望对 iOS 8 兼容性的代码进行大量更改,但在 iPad 上使用 UIActionSheet 时遇到了几个问题。

例如,我在使用 UIActionSheet 时遇到此异常:

UIPopoverPresentationController (<_UIAlertControllerActionSheetRegularPresentationController: 0x7c57bf90>) should have a non-nil sourceView or barButtonItem set before the presentation occurs.

我知道最好使用新的 UIAlertController,但是为了继续使用 UIActionSheet,是否有任何解决方法?

同样在 UIActionSheet 实际显示的地方(无一例外)它包含一个箭头 + 它不像以前那样居中(iOS7) - 我正在使用 showInView(也尝试使用 showFromRect 但得到相同的结果) .

【问题讨论】:

  • 您是否使用弹出框在 iPad 上展示UIAlertController
  • 我仍然不想迁移到新的 UIAlertController,我正在使用 UIActionSheet。
  • 我在我们的应用程序中看到了同样的问题。 UIActionSheet 似乎在 iOS 8 中被破坏了。不幸的是,UIAlertController 的 API 非常不同,因此编写支持这两种操作系统版本的代码是很痛苦的。
  • 我通过添加 UIActionSheet 类别找到了解决方案阅读我的问题我写了有问题的解决方案,stackoverflow.com/questions/24363761/…

标签: ios ipad ios8 uiactionsheet uialertcontroller


【解决方案1】:

从文档中可以清楚地看出 UIActionSheet 已被弃用。意味着您仍然可以使用它,但将来可能会失败或将被完全删除。

我强烈建议您更新到 UIAlertController。

您在 iPad 上遇到的例外情况很明显。由于具有样式 actionSheet 的 UIAlertController 需要 sourceView (将显示来自实际控制器的视图),因为它不再是全屏(就像在 iPhone 上一样)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-06-18
    • 1970-01-01
    • 1970-01-01
    • 2015-02-22
    • 1970-01-01
    • 2015-10-13
    • 2011-05-03
    • 2011-08-21
    相关资源
    最近更新 更多