由于弹出窗口,应用在 iPad 上测试时崩溃
App crashes when testing on iPad because of pop-over
我已经在这里阅读并搜索了答案,有人说在 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)
}
}
这是由于 iOS 中的更改引起的 8. 您必须为 iPad 使用 UIModalPresentationPopover。
这里有另一个堆栈溢出问题的详细描述:Presenting a UIAlertController properly on an iPad using iOS 8
我已经在这里阅读并搜索了答案,有人说在 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)
}
}
这是由于 iOS 中的更改引起的 8. 您必须为 iPad 使用 UIModalPresentationPopover。
这里有另一个堆栈溢出问题的详细描述:Presenting a UIAlertController properly on an iPad using iOS 8