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

时间:2013-01-19 14:03:09

标签: iphone ios uitableview

非常非常基本。我不明白。当表格加载时以及切换编辑时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;
}

谢谢!

1 个答案:

答案 0 :(得分:13)

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

Reorder control isn't displayed on table view

您还必须实施

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

<强>夫特

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

func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
    //code
}