tableView(_:moveRowAt:to:)
is a delegate method, meaning it is a method that you should implement and let the system call you, not the other way around — normally you should not call a delegate method yourself.
If you want to tell the system to move a row, simply call moveRow(at:to:)
of the table view, e.g.
func tableView(_ tableView: UITableView, didSelectRowAt ip: IndexPath) {
tableView.moveRow(at: ip, to: IndexPath(row: 0, section: ip.section))
}
After communicating with OP, want OP actually wants to reorder the model to push the selected item to the end. The typical way to do this is something like:
func tableView(_ tableView: UITableView, didSelectRowAt ip: IndexPath) {
// update the model.
model[ip.row].value = maxOfValue + 1
sortModelAgain()
// reload the model (note: no animation if using this)
tableView.reloadData()
}
or, if you'd like to manually keep the view and model in sync:
func tableView(_ tableView: UITableView, didSelectRowAt ip: IndexPath) {
// update the model.
model[ip.row].value = maxOfValue + 1
sortModelAgain()
// change the view to keep in sync of data.
tableView.beginUpdates()
let endRow = tableView.numberOfRows(inSection: ip.section) - 1
tableView.moveRow(at: ip, to: IndexPath(row: endRow, section: ip.section))
tableView.endUpdates()
}