カスタムの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];
}
ログに正しいインデックス パスが返されますが、テーブルビュー内の行は削除されません。誰でも私を助けることができますか?
敬具