UITableViewRowAction was deprecated in iOS 13.0

10,424

Solution 1

  func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
    let contextItem = UIContextualAction(style: .destructive, title: deleteActionTitle) {  (contextualAction, view, boolValue) in
        //Code I want to do here 
    }
    let swipeActions = UISwipeActionsConfiguration(actions: [contextItem])

    return swipeActions
}

Solution 2

You can use the UISwipeActionsConfiguration over UITableViewRowAction such as

override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {

  return UISwipeActionsConfiguration()
}
Share:
10,424

Related videos on Youtube

user1828845
Author by

user1828845

Updated on June 20, 2020

Comments

  • user1828845
    user1828845 about 4 years

    I am trying to upgrade code of my project and found this warning

     func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
        let deleteRowAction = UITableViewRowAction(style: .destructive, title: deleteActionTitle) { [unowned self] (_, indexPath) in
            //code you want to execute        }
        return [deleteRowAction]
    }
    
  • Matt Robinson
    Matt Robinson almost 4 years
    So it's clear since it's inferred from the answer, UIContextualAction is a drop in replacement for UITableViewRowAction. So, the migration ends up being something like: 1. Add trailingSwipeActionsConfigurationForRowAt delegate method. 2. Change references to UITableViewRowAction to UIContextualAction. The initializer will be slightly different in ObjC. 3. Pass the actions array to the UISwipeActionsConfiguration creation method instead of directly returning it.