I have an Edit button in my navigation bar, and I have an table view.
My edit button calls an -editAction method.
And then, I have this piece of code to delete a cell, but I don't know how I can make the edit button to call this code...or how the edit button can let the table view display those red delete circles for every cell, which then trigger this:
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the managed object at the given index path
NSManagedObject *eventToDelete = [eventsArray objectAtIndex:indexPath.row];
[managedObjectContext deleteObject:eventToDelete];
// Update Event objects array and table view
[eventsArray removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
// Commit the change
NSError *error;
if (![managedObjectContext save:&error]) {
// Handle the error
}
}
}