I'm building an app that needs to use trailing actions for a UITableView, I configured trailingSwipeActionsConfigurationForRowAt
as follows:
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
if indexPath == IndexPath(row: 0, section: 0) {
return nil
}
let deleteAction = UIContextualAction(style: .normal, title: "") { [weak self] (_, _, completion) in
self?.onDeleteActionClicked(at: indexPath)
completion(true)
}
deleteAction.backgroundColor = .black
deleteAction.image = UIImage.sfSymbol(.trash, tintColor: .white)
let editAction = UIContextualAction(style: .normal, title: "") { [weak self] (_, _, completion) in
self?.onEditActionClicked(at: indexPath)
completion(true)
}
editAction.backgroundColor = .white
editAction.image = UIImage.sfSymbol(.edit)
let configuration = UISwipeActionsConfiguration(actions: [deleteAction, editAction])
configuration.performsFirstActionWithFullSwipe = false
return configuration
}
This implementation works on a physical device and other simulators running iOS 16.1
The delegate is set correctly since didSelectRowAt
is being called, no gestureRecognizers are added to the cells and seems to be working fine with simulators running iOS 16.1 and physical devices running the same iOS version
So apparently for this to work before iOS 15 you have to implement the following method in the DataSource:
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
// Custom logic goes in here
}