I want to add Edit action to display when the user swipes a table row. I used to be able to use the editActionsForRowAt
method, but it is now deprecated. And in the commit editingStyle
method, there is no action I need. How can I add actions for my cells?
Asked
Active
Viewed 2,512 times
2

VyacheslavBakinkskiy
- 1,185
- 9
- 15
-
The solution provided in the linked answer https://stackoverflow.com/a/73559407/5546378 seems to be a viable option for your problem. – Ghullam Abbas Jun 21 '23 at 09:16
2 Answers
8
Try the following method:
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let item = UIContextualAction(style: .destructive, title: "Delete") { (contextualAction, view, boolValue) in
//Write your code in here
}
item.image = UIImage(named: "deleteIcon")
let swipeActions = UISwipeActionsConfiguration(actions: [item])
return swipeActions
}

Dogan Altinbas
- 268
- 2
- 11
-
Thx, it works. Maybe you know how to add Image for this button? Image like Trash or other, you know. – VyacheslavBakinkskiy Sep 14 '20 at 06:13
0
There is a useful and simple to use library called 'SwipeCellKit', which solves your problem:

Donat Kabashi
- 384
- 4
- 10