Reordering Cells

You empower your users when you allow them to directly reorder the cells of a table. Figure 9-5 shows a table that displays the reorder control’s stacked gray lines. Users can apply this interaction to sort to-do items by priority, choose which songs should go first in a playlist, and so on. iOS ships with built-in table reordering support that’s easy to add to your applications.

Like swipe-to-delete, cell reordering support is contingent on the presence or absence of a single method. The tableView:moveRowAtIndexPath:toIndexPath method synchronizes your data source with the onscreen changes, similar to committing edits for cell deletion. Adding this method instantly enables reordering.

Get The Core iOS Developer’s Cookbook, Fifth 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.