我在我的应用程序中使用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)
}
并且我的错误:
因为应用程序呈现了一个样式为UIAlertControllerStyleActionSheet的UIAlertController()。 具有此样式的UIAlertController的modalPresentationStyle是UIModalPresentationPopover。 您必须通过警报控制器的popoverPresentationController提供此弹出窗口的位置信息。 您必须提供sourceView和sourceRect或barButtonItem中的任一项。 如果在呈现警报控制器时不知道此信息,则可以在UIPopoverPresentationControllerDelegate方法-prepareForPopoverPresentation中提供它。