Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle user click the "delete button " in setEditing in TableView?

I added a editButton on the table like this:

    self.navigationItem.leftBarButtonItem = self.editButtonItem;

and, having a setEditing method:

- (void) setEditing:(BOOL)editing animated:(BOOL)animated {
    [super setEditing:editing animated:animated];
    [self.watchListDetailTableView setEditing:editing animated:animated];
    if (editing) {
            // you might disable other widgets here... (optional)
    } else {
            // re-enable disabled widgets (optional)
    }
}

after I click the edit, I can have a cross and delete button, which method should I do to handle the delete button click? thank you.

like image 566
DNB5brims Avatar asked Sep 03 '10 05:09

DNB5brims


1 Answers

This should be it:

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

More Info Here

When users tap the insertion (green plus) control or Delete button associated with a UITableViewCell object in the table view, the table view sends this message to the data source, asking it to commit the change. (If the user taps the deletion (red minus) control, the table view then displays the Delete button to get confirmation.) The data source commits the insertion or deletion by invoking the UITableView methods insertRowsAtIndexPaths:withRowAnimation: or deleteRowsAtIndexPaths:withRowAnimation:, as appropriate.

like image 68
vodkhang Avatar answered Nov 01 '22 18:11

vodkhang