0

I am using the following code to show a delete button when the user swipes the tableview cell. I want to write Cancel instead of Delete in this button, how can i achieve this functionality??

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

And

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  if (editingStyle == UITableViewCellEditingStyleDelete) {
    //remove the deleted object from your data source.
    //If you're data source is an NSMutableArray, do this
    [self.dataArray removeObjectAtIndex:indexPath.row];
  }
}
sam-w
  • 7,478
  • 1
  • 47
  • 77
Anurag Dixit
  • 119
  • 2
  • 16
  • possible duplicate of [Custom Delete button On Editing in UITableView Cell](http://stackoverflow.com/questions/1615469/custom-delete-button-on-editing-in-uitableview-cell) – Sergey Kalinichenko Mar 01 '13 at 15:24
  • It appears that you would like to keep the functionality, but display a different button. In this case, scroll to the highest-voted answer to see how you can do what you want. – Sergey Kalinichenko Mar 01 '13 at 15:25

1 Answers1

2

If all you want to do is change the title of the button to "Cancel", then just implement the -tableView:titleForDeleteConfirmationButtonForRowAtIndexPath: method in your table view's delegate.

-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return @"Cancel";
}
macserv
  • 3,546
  • 1
  • 26
  • 36