2

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?

  • 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 Answers2

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
0

There is a useful and simple to use library called 'SwipeCellKit', which solves your problem:

SwipeCellKit Documentation

Donat Kabashi
  • 384
  • 4
  • 10