简体   繁体   English

轻按tableview单元格内的按钮时,触发UITableViewCellEditingStyleDelete

[英]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). 我有UITableViewCell的子类,也连接了icon(button)。 It look like this 看起来像这样

- (IBAction)didPressMinusButton:(id)sender {

    [self setEditing:YES animated:YES];

}

In my tableView I also have this 在我的tableView中我也有这个

- (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
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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