Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show the reorder controls in UITableView with delete buttons

I read the documentation about how to manage deletion and reordering of rows in a UITableView. I created the edit button and I'm able to delete rows. I would like the user to be able to reorder the rows as well. It seems simple, but I can't understand how to tell the cells that they can be moved.

To tell the rows they can be deleted I use the editingStyleForRowAtIndexPath, but how do I tell the cell it can also be moved and where do I set the showsReorderControl? I tried to place in cellForRowAtIndexPath, but nothing is shown.

Thanks!

like image 210
Luca Carlon Avatar asked Dec 08 '10 12:12

Luca Carlon


1 Answers

You have to say that rows can be moved:

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
  return YES;
}

and implement this delegate to update your data source:

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath

See Managing the Reordering of Rows of Table View Programming Guide for iOS

like image 195
Benoît Avatar answered Oct 21 '22 09:10

Benoît