15

I created an iOS application based on navigation-based application template, the application is backed by Core Data framework.

When clicking on Edit button, I want the rows to be reorder-able and delete-able.

When constructing cells, I added this line:

cell.showsReorderControl = YES;

And tableView:canMoveRowAtIndexPath: method returns YES.

But the reorder control isn't displayed in the row, Am I missing something?

Martin
  • 11,881
  • 6
  • 64
  • 110
Chiron
  • 20,081
  • 17
  • 81
  • 133

3 Answers3

31

From the UITableViewCell showsReorderControl docs:

For the reordering control to appear, you must not only set this property but implement the UITableViewDataSource method tableView:moveRowAtIndexPath:toIndexPath:. In addition, if the data source implements tableView:canMoveRowAtIndexPath: to return NO, the reordering control does not appear in that designated row.

antalkerekes
  • 2,128
  • 1
  • 20
  • 36
Benedict Cohen
  • 11,912
  • 7
  • 55
  • 67
  • I was not aware that tableView:moveRowAtIndexPath:toIndexPath: had to be implemented to make the move accessory appear. This solved my problem! Thanks! –  Jun 14 '11 at 03:44
12

The UITableView also has to be in editing mode, which it's not in by default. Usually you use a button or some other control to toggle between editing mode. To put the table view in editing mode (we assume you have a UITableViewController and your tableView property is properly set, if not, adjust for your environment):

// This line somewhere inside the UITableViewController will
// animate in the various editing controls and make sure they
// show up on your table.
[[self tableView] setEditing:YES animated:YES];
Jason Coco
  • 77,985
  • 20
  • 184
  • 180
  • Here is an imaginary screenshot to what will be happened when the Edit button (at the left of the navigation bar) is pressed? Is it possible to combine the deletion and ordering operations when Edit is clicked? http://dl.dropbox.com/u/3630641/4-%20Todolist%20Main%20-%20Edit.jpg – Chiron Jan 22 '11 at 18:11
1

try this . . .you have to implement these two methods to get that reorder control in editing mode

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

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

}
Shaik Riyaz
  • 11,204
  • 7
  • 53
  • 70