I'm building an app that needs to use trailing actions for a UITableView,开发者_如何学C 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
精彩评论