我在这里阅读并搜索了一个答案,有些人说在iOS 9中你不需要额外的代码来在iPad上弹出一个弹出窗口,我也尝试过其他两个相关问题的代码但它没有正常工作弹出窗口只显示删除而不取消。它适用于iPhone和iPhone plus.Here是我的代码:
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)
}
}
答案 0 :(得分:0)
这是由iOS 8中的更改引起的。您必须在iPad上使用UIModalPresentationPopover。
以下是另一个堆栈溢出问题的详细说明:Presenting a UIAlertController properly on an iPad using iOS 8