我正在构建一个需要为UITableView使用尾随动作的应用程序,我配置trailingSwipeActionsConfigurationForRowAt
如下:
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
}
此实现在运行iOS 16.1的物理设备和其他模拟器上工作
委托被正确设置,因为didSelectRowAt
正在被调用,没有手势识别器被添加到单元格中,并且似乎与运行iOS 16.1的模拟器和运行相同iOS版本的物理设备一起工作良好
显然要在iOS 15之前工作你必须在数据源中实现以下方法:
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
// Custom logic goes in here
}