Iphone 如何在按下accessoryType删除按钮时删除UITableView单元格?

Iphone 如何在按下accessoryType删除按钮时删除UITableView单元格?,iphone,uitableview,Iphone,Uitableview,我只有一个视野。每个单元格的右侧都有一个accessoryType符号(>),当我触摸tableview单元格时,它会向我推送一个新的Viewcontroller。很简单 现在的问题是,我想在我的tableview单元格中,当我触摸Draginside的accessoryType符号时,它会显示一个附件按钮(就像删除按钮一样)。当我按下删除按钮时。它将从tableview中删除单元格。您需要实现这两个委托 - (UITableViewCellEditingStyle)tableView:(UIT

我只有一个视野。每个单元格的右侧都有一个accessoryType符号(>),当我触摸tableview单元格时,它会向我推送一个新的Viewcontroller。很简单


现在的问题是,我想在我的tableview单元格中,当我触摸Draginside的accessoryType符号时,它会显示一个附件按钮(就像删除按钮一样)。当我按下删除按钮时。它将从tableview中删除单元格。

您需要实现这两个委托

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleDelete;

}
//替代以支持编辑表格视图

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{    
    if (editingStyle == UITableViewCellEditingStyleDelete) 
    {
    NSArray *objects = [NSArray arrayWithObjects:indexPath, nil];
        [tableView deleteRowsAtIndexPaths:objects withRowAnimation:UITableViewRowAnimationRight];   
    }   
} 

希望这对您有用。

不调用这两个TableView委托函数。不知道为什么会这样。知道为什么不调用这两个委托函数吗。