0

カスタムのtableviewCellを持つテーブルビューがあります。このテーブルビュー セルには、行を削除するためのボタンがあります。

まず、次のコードでこのテーブルビューを作成します。

   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];

データソースとして使用する予定配列があります。私の cellForRowAtIndex では、次のコードを使用してボタンをアクションにアタッチします。

 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];
}

ログに正しいインデックス パスが返されますが、テーブルビュー内の行は削除されません。誰でも私を助けることができますか?

敬具

4

1 に答える 1

0

メソッドも更新する必要がありますnumberOfRowsInSection。たとえば、要素を配列に保持している場合は、その要素を 1 つ削除して、更新された配列を に返しnumberOfRowsInSectionます。

于 2012-12-04T15:24:12.003 に答える