TableView commitEditingStyle and knowledge when Finish button is clicked

My controller inherits from UITableViewController with left button assigned 'editButtonItem'. How do I know when a user has clicked the Finish button after giving out all the deletions they want?

self.navigationItem.leftBarButtonItem = self.editButtonItem;

      

I am implementing

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

      

With this I can see when events are removed for each item in the table, but I would also like to know when the Finish button is clicked.

+2


source to share


2 answers


It turns out that I need to override:

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

      



This will tell me when the edit has finished.

+3


source


You can also use a customized UIBarButtonItem like 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";
    ...
  }
}

      



This way you can control the label of the Edit button and instead Save instead of Done if you have a Cancel button on the right.

0


source







All Articles