Reputation: 5078
Please be toleratant on this as I didn't find anything that helps me clearly.
I would like to allow row deletion in a TableView cells into my app.
I've been suggested to add the following in the viewDidLoad method:
self.navigationItem.rightBarButtonItem = self.editButtonItem;
but what's next ?
Thx for helping,
Stephane
Upvotes: 0
Views: 368
Reputation: 14662
To make your tableView go in editing mode,
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[self.tableView setEditing:editing animated:animated];
[super setEditing:editing animated:animated];
}
You also simply implement the -tableView:commitEditingStyle:forRowAtIndexPath:
method in UITableViewDelegate
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
[itemList removeObjectAtIndex:indexPath.row];
[table deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
}
}
Where itemList
is simply where you store your data in your UIViewController
.
Upvotes: 1