How to disable slide to delete for a UITableView

前端 未结 2 1038
醉酒成梦
醉酒成梦 2021-01-04 04:36

Does anybody know how to disable the \'slide-to-delete\' in a uitableview?

I still want to be able to delete the rows while the table is in editing mode.

相关标签:
2条回答
  • 2021-01-04 04:43

    Mine is:

    - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 
    {
       return self.editing ;
    }
    
    0 讨论(0)
  • 2021-01-04 04:59

    First, to confirm if a table cell can be deleted simply reply to canEditRowAtIndexPath.

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

    Then, to actually delete the table cell reply to 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];
      }
    }

    Good luck Mats Stijlaart!

    0 讨论(0)
提交回复
热议问题