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 send the message deleteRowsAtIndexPaths:withRowAnimation: to the UITableView to confirm the deletion. Moving a row, however, doesn’t require confirmation; the table view moves the row on its own authority and reports the move to its the data source by sending the message tableView:​moveRowAtIndexPath:​toIndexPath:. You just have to catch this message to update your data source to match the new order.

But before we can implement the data source method, we need to give the BNRItemStore a method to change the order of BNRItems in its allItems array. ...

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.