开发者

Delegate method on fingure swipe on a cell

开发者 https://www.devze.com 2023-01-31 01:49 出处:网络
Is there any delegate method called the moment one swipe on table开发者_JS百科 cell and delete button comes in from the right?

Is there any delegate method called the moment one swipe on table开发者_JS百科 cell and delete button comes in from the right?

I wanted to track the swipe and do some action there.

Also, which delegate method gets called when you tap on "Delete" button in the cell.

Delegate method on fingure swipe on a cell


The UITableViewDelegate method tableView:editingStyleForRowAtIndexPath: will be called before a row enters "edit" mode. This is called when you swipe a cell as well as when the table view receives the setEditing:animated message. If you have an Edit button that puts the table view into edit mode you need to be aware that will be called for each visible cell.

So you can do something like:

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView 
           editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView.editing) {
        return UITableViewCellEditingStyleDelete;
    }
    else {
        // do your thing
        return UITableViewCellEditingStyleDelete;
    }
}

When you tap the Delete button tableView:commitEditingStyle:forRowAtIndexPath: gets called.

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

    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // repsond to delete
    }     
}

And if you want to change the text of the Delete button you can use tableView:titleForDeleteConfirmationButtonForRowAtIndexPath:

If on the other side you don't want to display the Delete button but do something else you should look into UISwipeGestureRecognizer and handle it your self.

0

精彩评论

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