从UIBarButtonItem呈现UIAlertController

时间:2015-04-30 10:09:56

标签: ios iphone uibarbuttonitem uialertcontroller

我正在尝试显示UIAlertController中的UIBarButtonItem,就像点击操作按钮时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)
}

如果有人能帮助我,我将非常感激。

提前致谢!

1 个答案:

答案 0 :(得分:0)

我得出的结论是,无法在iPhone上显示UIAlertController作为popover。这并不像我最初想的那样在Facebook应用程序中做了什么,理由是你无法在UIAlertAction中添加图标。

我设法通过在我的故事板中添加一个UITableViewController并添加一个popover segue来解决它。遵循本教程帮助我:http://richardallen.me/2014/11/28/popovers.html