canMoveRowAtIndexPath不会被调用 - 但是canEditRowAtIndexPath可以调用

Tod*_*ddB 4 iphone uitableview ios

非常非常基本.我不明白.当表加载时和canEdit调用切换时,调用但不调用canMove.我究竟做错了什么?

- (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;
}
Run Code Online (Sandbox Code Playgroud)

谢谢!

Tod*_*ddB 13

对不起,这个问题在这里得到解答:

表视图上不显示重新排序控件

你还必须实施

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath 
Run Code Online (Sandbox Code Playgroud)

斯威夫特:

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

func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
    //code
}
Run Code Online (Sandbox Code Playgroud)