这两个 API 似乎得到了相同的结果。在哪种情况下使用一种优于另一种?
override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
let deleteAction = UITableViewRowAction(style: .destructive,
title: "Delete") { (action, indexPath) in
print("DELETE")
}
return [deleteAction]
}
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let DeleteAction = UIContextualAction(style: .destructive, title: "Delete", handler: { (action, view, success) in
print("Delete")
})
DeleteAction.backgroundColor = .red
return UISwipeActionsConfiguration(actions: [DeleteAction])
}
最佳答案
它的功能基本相同,但是自 iOS 11 发布以来就可以使用滑动操作并具有一些新功能:
此外,您应该使用滑动操作,因为它们是首选,并且在将来的更新中 UITableViewRowActions
将被弃用 UITableView
标题注释如何告诉我们:
Use -
tableView:trailingSwipeActionsConfigurationForRowAtIndexPath:
instead of this method, which will be deprecated in a future release.
关于ios - UITableViewRowAction 与 UISwipeActionsConfiguration,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53577995/