I’ve got a UITableView which has been created programatically. I’m now trying to add the ability to delete the rows using the edit mode.
I’ve added the default way of doing this:
self.navigationItem.leftBarButtonItem = self.editButtonItem;
When you tap the button, it enters edit mode and the button changes to the ‘done’ button.
However, when I “slide to delete” the row, which just shows the delete button, the existing edit button doesn’t change to ‘done’.
Is there something I need to do extra because I created the table view programatically?
Below is the code for my tableview:
- (void)viewDidLoad
{
self.voucherTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 36, 320, self.view.frame.size.height - 36) style:UITableViewStylePlain];
self.voucherTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
self.voucherTableView.delegate = self;
self.voucherTableView.dataSource = self;
[self.view addSubview:self.voucherTableView];
self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
// Default table view data source methods go here
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];
[self.voucherTableView setEditing:editing animated:animated];
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleDelete;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
// Commit the delete
}
}
Here is my answer for you: the button doesn’t change to “Done” because a slide to delete does not actually have to be done in “Edit” mode and it does not put you into edit mode.
You could force it into Edit mode if you wish when you perform the delete, not sure why you would want to do that?