我在这里阅读并搜索了答案,有人说在 iOS 9 中你不需要额外的代码来在 iPad 上弹出弹出窗口,我也尝试了其他两个相关问题中的代码但是它无法正常工作弹出窗口只显示删除而不是取消。它在 iPhone 和 iPhone plus 上运行良好。这是我的代码:
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == .Delete {
let item = itemStore.allItems[indexPath.row]
let title = "Delete \(item.name)?"
let message = "Are you sure you want to delete this item"
let ac = UIAlertController(title: title, message: message, preferredStyle: .ActionSheet)
let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)
ac.addAction(cancelAction)
let deleteAction = UIAlertAction(title: "Delete", style: .Destructive, handler: { (action) -> Void in
self.itemStore.removeItem(item)
self.tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
})
ac.addAction(deleteAction)
presentViewController(ac, animated: true, completion: nil)
}
}
最佳答案
这是由 iOS 8 中的更改引起的。您必须为 iPad 使用 UIModalPresentationPopover。
这是另一个堆栈溢出问题的详细描述:Presenting a UIAlertController properly on an iPad using iOS 8
关于ios - 由于弹出窗口,在 iPad 上测试时应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34903909/