开发者

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

开发者 https://www.devze.com 2023-01-14 01:56 出处:网络
I added a editButton on the table like this: self.navigationItem.leftBarButtonItem = self.editButtonItem;

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 ca开发者_运维问答n have a cross and delete button, which method should I do to handle the delete button click? thank you.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消