问题
Is it possible to implement an undo manager
when you delete a row in a tableView
?
I have read about undo manager
and you have to set the viewController
as becomeFirstResponder()
.
The problem is that I am using a tableView
inside a collectionViewCell
How shall I proceed with registering an undo?
I tried the following and it doesn't seem to work
@IBAction func tableButtonUndo(_ sender: Any) {
print("undo working")
undoItem()
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
indexPathSelected = indexPath.row
if tableView == ordersTableView {
print("tap in kitchen table view")
self.removeItemKitchen()
ordersTableView.reloadData()
}
}
func removeItemKitchen() {
orderSingle.orderListFormatted.remove(at: indexPathSelected)
undoManager?.registerUndo(withTarget: MyVC(), selector: #selector(self.undoItem), object: nil)
undoManager?.setActionName("Undo")
}
func undoItem() {
undoManager?.registerUndo(withTarget: MyVC(), selector: #selector(self.removeItemKitchen), object: nil)
undoManager?.setActionName("Undo")
undoManager?.undo()
}
This code should undo the operation, but instead, I get a redo, it deletes the next row.
I would like to recover the deleted row by tapping the undo button
来源:https://stackoverflow.com/questions/41623854/undo-manager-for-tableview-row-delete