Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable slide to delete for a UITableView

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.

like image 986
Mats Stijlaart Avatar asked Sep 10 '10 13:09

Mats Stijlaart


2 Answers

Mine is:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 
{
   return self.editing ;
}
like image 68
iyusa Avatar answered Sep 21 '22 04:09

iyusa


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!

like image 35
rjobidon Avatar answered Sep 19 '22 04:09

rjobidon