Now, let's implement the reordering of cells:
- To enable the reordering of cells, you need exactly three steps. The first step is to enable the showing of the reordering control in cells. To do this, just do the following in the cellForRow method:
cell?.showsReorderControl = true
- The second step is to override the canMoveRowAt function in the data source:
func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool { return true }
- This will ask you if the row at the given indexPath can be moved or not. As all the rows in our app can be moved, just return true for all.
- The third step is to override the moveRowAt function, which is the function that performs the moving in ...