如何禁用UITableView的幻灯片删除

Mat*_*art 14 iphone uitableview

有人知道如何在uitableview中禁用"幻灯片删除"吗?

我仍然希望能够在表处于编辑模式时删除行.

小智 30

我的是:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 
{
   return self.editing ;
}
Run Code Online (Sandbox Code Playgroud)


rjo*_*don 13

首先,要确认是否可以删除表格单元格,只需回复canEditRowAtIndexPath即可.

-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
  // Return YES or NO
  return(YES);
  }
}
Run Code Online (Sandbox Code Playgroud)

然后,实际删除表单元格回复commitEditingStyle.

-(void)tableView:(UITableView *)tv commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  if (editingStyle == UITableViewCellEditingStyleDelete) {
  // Delete your data

  // Delete the table cell
  [self.tableView deleteRowAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
  }
}
Run Code Online (Sandbox Code Playgroud)

好运Mats Stijlaart!

  • 这是如何回答这个问题的? (2认同)