views:

782

answers:

2

My controller inherits from UITableViewController with the left button assigned to 'editButtonItem'. How can I find out when the user has tapped the "Done" button after issuing all of the deletes they want?

self.navigationItem.leftBarButtonItem = self.editButtonItem;

I'm implementing

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

With this, I see when the deletes occur for each item in the table but I would also like to know when the "Done" button is hit.

+1  A: 

Turns out that I need to override:

- (void)setEditing:(BOOL)editing animated:(BOOL)animated

This will tell me when editing has ended.

Alexi Groove
Do you need to parent's same method first in your overwrite codes?
David.Chu.ca
A: 

You may also use a customized UIBarButtonItem as Edit:

editButton = [[UIBarButtonItem alloc] initWithTitle:@"Edit"
  style:UIBarButtonItemStyleBordered target:self action:@selector(toggleEditing)];
editButton.possibleTitles = [NSSet setWithObjects:@"Edit", @"Save", nil];
self.navigationItem.leftBarButtonItem = editButton;
isEdit = YES; // class level flag

- (void)toggleEditing {
  if (isEdit) {
    isEdit = NO;
    editButton.text = @"Save";
    ...

  }
  else {
    isEdit = YES;
    editButton.text = @"Save";
    ...
  }
}

In this way, you have control of the caption of Edit button and change it to "Save" instead "Done" if you have a Cancel button on the right.

David.Chu.ca