Reputation: 11749
I am looking at various possible ways to implement delete-edit-copy feature on the UITableViewCell
elements of a UITableView
.
The one I am trying now is based on the usage of the following methods:
[tableView setEditing:YES animated:YES];
- (void)tableView:(UITableView *)tableView
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath;
I can see some advantages to use this approach, but there is one problem:
When I try it, I can make the red "Delete" button appear and work, but that is all.
Is there a mechanism by which I could also have "edit" and "copy" buttons ? Or is it just not possible?
Thanks for any helpful information.
Upvotes: 2
Views: 10558
Reputation: 869
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
[DummyData removeObjectAtIndex:indexPath.row];
[_tableView reloadData];
}
}
Use this code. Hope it helps and please do the same with UITableViewCellEditingStyleInsert
Upvotes: 1
Reputation: 8180
EDIT
I just understood that you are referring to the cell, not the TableView. For the cell, the following styles are provided:
Further styles you have to implement on your own.
Original Answer
You can use the editButtonItem
method of UIViewController
. It returns a bar button item that toggles its title and associated state between "Edit" and "Done" (but not "Copy"). The default button action already invokes the setEditing:animated:
method.
If you want another state, your have to create your own BarButtonItem.
Upvotes: 3