这两个API似乎获得了相同的结果。在哪种情况下,最好使用一种而不是另一种?
override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
let deleteAction = UITableViewRowAction(style: .destructive,
title: "Delete") { (action, indexPath) in
print("DELETE")
}
return [deleteAction]
}
Run Code Online (Sandbox Code Playgroud)
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])
}
Run Code Online (Sandbox Code Playgroud)
它的作用基本相同,但自 iOS 11 发布以来,滑动操作可用,并具有一些新功能:
此外,您应该使用滑动操作,因为它们是首选操作,并且将来UITableViewRowActions不推荐使用UITableView标题注释如何告诉我们的更新:
使用 -
tableView:trailingSwipeActionsConfigurationForRowAtIndexPath:而不是此方法,它将在未来版本中弃用。
| 归档时间: |
|
| 查看次数: |
589 次 |
| 最近记录: |