【问题标题】:Present UIAlertController from UIBarButtonItem从 UIBarButtonItem 呈现 UIAlertController
【发布时间】:2015-06-10 19:52:32
【问题描述】:

我正在尝试从UIBarButtonItem 显示UIAlertController,就像在Facebook 应用程序的网络浏览器中单击操作按钮时一样。但一直没有成功。一直在 Stack Overflow、Google、Github 等上搜索,但没有找到我要找的东西。

您可以在此处查看 Facebook 应用程序中的外观:UIAlertController in the Facebook app

下面是我尝试过的代码,但我注意到popoverPresentationController 属性是nil

func showActionSheet(sender: AnyObject) {
    var optionsAlert = UIAlertController(title: nil, message: nil, preferredStyle: .ActionSheet)

    // Add the actions

    optionsAlert.modalPresentationStyle = .Popover
    optionsAlert.popoverPresentationController?.barButtonItem = sender as! UIBarButtonItem

    presentViewController(optionsAlert, animated: true, completion: nil)
}

如果有人能帮我解决这个问题,我将不胜感激。

提前致谢!

【问题讨论】:

  • 真的吗?你确定吗?它不应该是零。不是我运行上面的代码。
  • 是的,我确定。我不知道我尝试了多少方法让它发挥作用。我尝试将 modalInPopover 设置为 true,但它仍然不起作用。我在网上搜索过,但我只找到未回答的问题。请帮忙

标签: ios iphone uibarbuttonitem uialertcontroller


【解决方案1】:

我得出的结论是,在 iPhone 上无法将 UIAlertController 显示为弹出框。这不是我最初想的那样在 Facebook 应用程序中所做的事情,因为您无法将图标添加到 UIAlertAction。

我设法通过向我的故事板添加一个 UITableViewController 并添加一个弹出框来解决它。遵循本教程对我有帮助:http://richardallen.me/2014/11/28/popovers.html

【讨论】:

    猜你喜欢
    • 2015-08-09
    • 1970-01-01
    • 2015-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-06
    相关资源
    最近更新 更多