1
私はUITableViewController
を持っています。ユーザーが行を削除できるように設定されています。アラート確認でUITableViewControllerの行を削除する
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"t" message:@"del?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Delete", nil];
[alert show];
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSIndexPath *path = [self.tableView indexPathForSelectedRow];
if (buttonIndex != [alertView cancelButtonIndex]) {
//my code to delete from the data source is here. it works fine.
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:path] withRowAnimation:UITableViewRowAnimationFade];
}
}
問題は、実際にtableView
から行を削除するはずだと最後の行である:これは私の削除アクションのハンドラのコード、およびUIAlertView
ためのデリゲートメソッドです。 UIAlertView
の代わりに、最初のメソッドでデータソースから削除したコードを置くとうまくいきます。
これを行う正しい方法は何ですか?