Panda Pig • Patty original or translated works. Welcome reprint, Reprint please indicate the source.
If you feel that the writing is not good please more advice, if you feel good please support a lot of praise. Thank you! Hopy;)
We know that using UITableView's delegate method Canmoverowatindexpath can determine whether a row of cells can be moved, that is, whether the source cell can be moved, but if we want to control whether it can be moved to the target index?
One idea is to determine the target index in Moverowatindexpath: If not allowed to move, then do the reverse action, that is, delete the cell at the destination index position and then add it back to the source index.
However, this cannot be achieved because the source cell has not been moved to the destination index, so it cannot be deleted. But Moverowatindexpath: After the method is finished, the control of the mobile operation is lost.
In fact, there is a simple way, if you do not want to make the move operation, including any need to change the interface, you simply re-refresh the TableView view. Because your underlying data is not changed, the interface will not change after refreshing the view, which is equivalent to undoing the move operation, And there are animation effects:
As shown above we prohibit the move of the Add cell and prohibit any other cell from moving to the back of the Add cell, which is to ensure that the add cell is always in the last row of the view.
UITableView How to undo a move operation