IOS 13
UITableView
编辑菜单
UITableViewDelegate
1//废弃的API
2func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
3 let delete = UITableViewRowAction(style: .destructive, title: "删除") { action, indexPath in
4
5 }
6 let modify = UITableViewRowAction(style: .normal, title: "修改") { action, indexPath in
7
8 }
9 return [delete, modify]
10}
11//代替的API
12//右侧轻扫菜单
13func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
14 let deleteAction = UIContextualAction(style: .destructive, title: "删除") { action, view, result in
15
16 }
17
18 let modifyAction = UIContextualAction(style: .normal, title: "修改") { action, view, result in
19
20 }
21
22 let swipeActions = UISwipeActionsConfiguration(actions: [deleteAction, modifyAction])
23
24 return swipeActions
25}
26//左侧轻扫菜单
27func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
28 let selectAction = UIContextualAction(style: .normal, title: "选择") { action, view, result in
29
30 }
31 let swipeActions = UISwipeActionsConfiguration(actions: [selectAction])
32
33 return swipeActions
34}