在UITableView中删除行但不要使用“删除”按钮

时间:2013-07-05 04:30:45

标签: ios iphone uitableview nsindexpath

我有问题,我想在UITableView中删除行但不要使用滑动按钮删除。我希望在条件之后调用函数removeCell。我的问题是我无法删除UITableView中的第一行,因为我不知道要删除的行的indexPath。

如果我轻扫“删除”按钮,则效果很好。 但我想不要使用删除按钮。

- (void)tableView:(UITableView *)aTableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
    deleteindexPath = indexPath;
    /*[_tableView beginUpdates];

    if (editingStyle == UITableViewCellEditingStyleDelete) {
        [_tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }
    [_tableView endUpdates];*/
    [self removeCell];
}

removeCell():

    -(void) removeCell
{
    [_tableView beginUpdates];

        [_tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:deleteIndexPath] withRowAnimation:UITableViewRowAnimationFade];
   // }
    [_tableView endUpdates];
}

我尝试在deleteIndexPath = [_tableView indexPathForCell:cell];中设置cellForRowAtIndexPath()但不起作用,崩溃。

你能提出建议吗?

1 个答案:

答案 0 :(得分:1)

试试这个

-(void) removeCell
{    
    [_tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:deleteIndexPath] withRowAnimation:UITableViewRowAnimationFade];
    //Now remove data from your tableArray also..
    [_tableView reloadData];
}