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()
}
Related videos on Youtube
Author by
user1828845
Updated on June 20, 2020Comments
-
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] }
-
Martin R about 5 yearsFirst SO search result: stackoverflow.com/a/53578303/1187415.
-
-
Matt Robinson almost 4 yearsSo it's clear since it's inferred from the answer,
UIContextualAction
is a drop in replacement forUITableViewRowAction
. So, the migration ends up being something like: 1. AddtrailingSwipeActionsConfigurationForRowAt
delegate method. 2. Change references toUITableViewRowAction
toUIContextualAction
. The initializer will be slightly different in ObjC. 3. Pass the actions array to theUISwipeActionsConfiguration
creation method instead of directly returning it.