【发布时间】:2015-03-21 07:28:08
【问题描述】:
我在我的应用程序中使用 ActionSheet。在我的 iPhone 上它可以工作,但在 iPad 模拟器上却不行。
这是我的代码:
@IBAction func dialog(sender: AnyObject) {
let optionMenu = UIAlertController(title: nil, message: "Choose Option", preferredStyle: .ActionSheet)
let deleteAction = UIAlertAction(title: "Delete", style: .Default, handler: {
(alert: UIAlertAction!) -> Void in
println("Filtre Deleted")
})
let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: {
(alert: UIAlertAction!) -> Void in
println("Cancelled")
})
optionMenu.addAction(deleteAction)
optionMenu.addAction(cancelAction)
self.presentViewController(optionMenu, animated: true, completion: nil)
}
我的错误:
由于未捕获的异常“NSGenericException”而终止应用程序, 原因:'您的应用程序提供了一个 UIAlertController () 风格 UIAlertControllerStyleActionSheet。 modalPresentationStyle 的 这种风格的 UIAlertController 是 UIModalPresentationPopover。你 必须通过警报提供此弹出窗口的位置信息 控制器的 popoverPresentationController。您必须提供 sourceView 和 sourceRect 或 barButtonItem。如果这个信息是 当您出示警报控制器时不知道,您可以在 UIPopoverPresentationControllerDelegate 方法 -prepareForPopoverPresentation。'
【问题讨论】:
-
这个Link 可以帮助你。
-
ios 8 及更高版本没有操作表 UIActionController 实例,您需要将类型设置为 UIAlertControllerStyleActionSheet .... 这可能会对您有所帮助 .... 虽然 iPad 建议使用 uipopover ....
-
您必须在 iPad 上将其呈现为弹出框
标签: ios ipad swift uiactionsheet