ios - 由于弹出窗口,在 iPad 上测试时应用程序崩溃

标签 ios iphone swift ipad xcode7

我在这里阅读并搜索了答案,有人说在 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/

相关文章:

ios - YouTubePlayer - 更改 iOS 背景颜色

javascript - 写一个手机电台APP——Javascript/HTML/CSS可行吗,还是需要原生化?

ios - 设置AVCaptureDevice格式范围

ios - iPhone 未从 Apple Watch 接收应用程序上下文

ios - Swift 中从 UIScrollView 到其他 View 的 Segue

ios - 如何在两个 UIViewControllers 上工作,一个在 swift 中,另一个在 objective-c 中..?

swift - 为什么我的 TableView scrollToRow 只能部分滚动?

objective-c - 防止键盘 split 并阻止它

ios - IOS 中表格 View 单元格点击的背景颜色更改

ios - AFNetworking 2.0 和 Nginx 之间的文件缓存