Iphone 无法从自定义tableview单元格按钮中删除行

Iphone 无法从自定义tableview单元格按钮中删除行,iphone,objective-c,ios,uitableview,Iphone,Objective C,Ios,Uitableview,我有一个带有自定义tableviewCell的tableview。在这个tableview单元格中,我有一个用于删除行的按钮 首先,我通过以下代码创建这个tableview UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 70, 320, 150) style:UITableViewStylePlain]; tableView.autoresizingMask = UIViewAut

我有一个带有自定义tableviewCell的tableview。在这个tableview单元格中,我有一个用于删除行的按钮

首先,我通过以下代码创建这个tableview

   UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 70, 320, 150) style:UITableViewStylePlain];
    tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.backgroundColor = [UIColor blackColor];
    tableView.separatorStyle = normal;
    [tableView reloadData];
我有一个约会数组,用作我的数据源。在我的CellForRowatinex中,我使用以下代码将我的按钮附加到操作

 cell.btnDelete.tag = indexPath.row;
    [cell.btnDelete addTarget:self action:@selector(deleteAppointment:) forControlEvents:UIControlEventTouchUpInside];
然后我有我的行动本身

-(void)deleteAppointment:(id) sender{
        NSLog(@"till here");
    UIButton *button = (UIButton *)sender;
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:button.tag inSection:0];
    NSLog(@"indexpathc: %d",indexPath.row);

    [tableView beginUpdates];
    [tableView deleteRowsAtIndexPaths: [NSArray arrayWithObject:indexPath]
                     withRowAnimation: UITableViewRowAnimationFade];
    [_exceptions removeObjectAtIndex:indexPath.row];
    [tableView endUpdates];
}
它在日志中返回正确的索引路径,但不会删除tableview中的行。有人能帮我吗


亲切问候

您还需要更新方法
numberofrowsin部分
。例如,如果要将元素保留在数组中,请从数组中删除一个元素,并在
numberofrowsinssection
中返回更新后的数组