简体   繁体   中英

Trigger UITableViewCellEditingStyleDelete when button inside tableview cell is tapped

在此处输入图片说明

This is my cell what I need to achieve is when I tap the icon on left side of my cell it trigger as if the user swipe the cell.

I have a subclass of UITableViewCell also I wired the icon(button). It look like this

- (IBAction)didPressMinusButton:(id)sender {

    [self setEditing:YES animated:YES];

}

In my tableView I also have this

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    //my code for deletion here
}

I would like to achieve when the user tap the icon in left side of my cell I should show the remove or delete. basically like swipe but in this case I just trigger it by tap.

You mean that when user tap on minus icon on left then the remove functionality should work instead of swipe.Right ?

If yes, then just remove this code or make comments for this

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    //my code for deletion here
} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM