您可以简单地创建委托方法,trailingSwipeActionsConfigurationForRowAt,如下所示,并根据需要对其进行自定义:
extension YOURVIEWCONROLLER: UITableViewDelegate{
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let removeAction = UIContextualAction(style: .destructive, title: "Remove") { action, view, complete in
//Your code
Utility.main.showAlert(message: "Removed Pressed", title: "Alert")
complete(true)
}
doneAction.backgroundColor = UIColor.red
return UISwipeActionsConfiguration(actions: [removeAction])
}
}