Да. Вы можете реализовать следующий метод:
Сначала ViewController имеет свойство с именем isEditing, которое определяет, находится ли ячейка в редактируемом состоянии.
extension UIViewController {
open var isEditing: Bool
open func setEditing(_ editing: Bool, animated: Bool)
open var editButtonItem: UIBarButtonItem { get }
}
Затем необходимо реализовать методы делегата UITableView. например:
// Override to support conditional editing of the table view.
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
// Return false if you do not want the specified item to be editable.
return true
}
// Override to support editing the table view.
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
// Delete the row from the data source
tableView.deleteRows(at: [indexPath], with: .fade)
} else if editingStyle == .insert {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
Наконец, когда переменная isEditing имеет значение true, вы можете получить то, что хотите выше.