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 sends the data source the message tableView:moveRowAtIndexPath:toIndexPath: to report the move. 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 PossessionStore a method to change the order of Possessions in its allPossessions array. ...

Get iOS Programming: The Big Nerd Ranch Guide, Second Edition 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.