Moving Rows

To change the order of rows in a UITableView, you will use another method from the UITableViewDataSource protocol – tableView(_:moveRowAtIndexPath:toIndexPath:).

To delete a row, you had to call the method deleteRowsAtIndexPaths(_:withRowAnimation:) on the UITableView to confirm the deletion. Moving a row, however, does not require confirmation: The table view moves the row on its own authority and reports the move to its data source by calling the method tableView(_:moveRowAtIndexPath:toIndexPath:). You implement this method to update your data source to match the new order.

But before you can implement this method, you need to give the ItemStore a method to change the order of items in its allItems array.

In ...

Get iOS Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.