Reputation: 119
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];
}
}
Upvotes: 0
Views: 502
Reputation: 3554
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";
}
Upvotes: 2