gpt4 book ai didi

swift - UITableViewRowAction - 延迟关闭动画直到确认

转载 作者:行者123 更新时间:2023-11-30 11:14:48 28 4
gpt4 key购买 nike

我用谷歌搜索了两个多小时,没有发现任何有用的东西:我有一个带有 editActions 的 tableView 。当我按下该操作时,我会显示一个包含附加信息/需要确认的警报 Controller 。

显示alertController后,editActions立即被取消。我想等待关闭动画,直到我的 alterController 被关闭。

这是我的代码:

override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
let delete = UITableViewRowAction(style: .destructive, title: "delete") { (action, indexPath) in
let cell = tableView.cellForRow(at: indexPath) as? DocumentTableViewCell

self.askUserForDeleteFile() { (shallDelete) in
if shallDelete {
self.imageDocumentHandler?.deleteDocumentOfDatabase(self.fetchedResultsController.object(at: indexPath))
}
}
}

let deselect = UITableViewRowAction(style: .normal, title: "kickout") { (action, indexPath) in
self.folder?.removeFromDocuments(self.fetchedResultsController.object(at: indexPath))
}

deselect.backgroundColor = UIColor(displayP3Red: 247/255, green: 162/255, blue: 180/255, alpha: 1.0)

return [deselect,delete]
}

func askUserForDeleteFile(completion: @escaping (Bool)->()) {
let alertController = UIAlertController(title: "delete document?", message: nil, preferredStyle: .actionSheet)

let deleteAction = UIAlertAction(title: "delete", style: .destructive) { (_) in
completion(true)
}
let cancelAction = UIAlertAction(title: "cancel", style: .cancel) { (_) in
completion(false)
}

alertController.addAction(deleteAction)
alertController.addAction(cancelAction)

self.present(alertController, animated: true, completion: nil)
}

最佳答案

这是 editAction 滑动删除的标准行为。但是,如果您的目标是 IOS 11 或更高版本,那么您可以使用新方法来实现您的需求。你可以做这样的事情。

func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {

let delete = UIContextualAction.init(style: UIContextualAction.Style.destructive, title: "delete", handler: { (action, view, completion) in

let cell = tableView.cellForRow(at: indexPath) as? DocumentTableViewCell

self.askUserForDeleteFile() { (shallDelete) in
if shallDelete {
self.imageDocumentHandler?.deleteDocumentOfDatabase(self.fetchedResultsController.object(at: indexPath))
}
completion(true)
}
})

let deselect = UIContextualAction.init(style: UIContextualAction.Style.normal, title: "kickout", handler: { (action, view, completion) in
self.folder?.removeFromDocuments(self.fetchedResultsController.object(at: indexPath))
completion(true)
})

let config = UISwipeActionsConfiguration(actions: [delete, deselect])
return config
}

除非指定,否则完成将阻止动画被关闭。但是,如果您的目标是 IOS 10,您仍然需要 editAction 方法。

关于swift - UITableViewRowAction - 延迟关闭动画直到确认,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51849834/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com