Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

canMoveRowAtIndexPath doesn't get called - but canEditRowAtIndexPath does

Very very basic. I don't understand. When the table loads and when Edit is toggled canEdit is called, but not canMove. What am I doing wrong?

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
  NSLog(@"canEdit=%d", indexPath.row);  
  // output is as expected, "canEdit" for each row
  return (indexPath.section == 1) ? YES : NO;
}

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
  NSLog(@"canMove=%d", indexPath.row);
  // nothing. No output
  return (indexPath.section == 1) ? YES : NO;
}

Thanks!

like image 880
ToddB Avatar asked Dec 11 '22 18:12

ToddB


1 Answers

Sorry, the issue is answered here:

Reorder control isn't displayed on table view

You have to also implement

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

Swift:

func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
    return true
}

func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
    //code
}
like image 93
ToddB Avatar answered May 21 '23 02:05

ToddB