0
votes

I wanted to know the difference between these. The tableView method & the UITableViewController method.

tableView.moveRow(at:, to:)      
tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath)

Wanted to know the difference and when to use them, cause I used the tableView.moveRow(at: SourceIndexPath, to: DestinationIndexPath) inside the tableView(tableView:, moveRowAt:, to:). But the App crashes.

Would appreciate the help.

Crash Error:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (2) must be equal to the number of rows contained in that section before the update (3), plus or minus the number of rows inserted or deleted from that section (0 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (1 moved in, 0 moved out).

1
Could you paste the crash / error message. Your cells rely on the data source, so your model should be reflective of this. Are you using NSFetchedResultsController ? - user1046037
No not using fetchController. - Luis Ramirez
Paste the error / crash - user1046037
okay added the crash error - Luis Ramirez
Read the error message closely "... plus or minus the number of rows moved into or out of that section.." - Gruntcakes

1 Answers

0
votes

tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath)

This is the delegate method of table view. It is asking the view controller tasks to perform.

Meanwhile tableView.moveRow(at:, to:) is the method programatically to move row. You are calling tableView.moveRow(at:, to:) in the delegate method causing the next changes before one change is done.