テーブルビューセルを削除したいのですが、そのアクションが発生する前に、ユーザーにアラートビューを提供したいと思います。私はこれを得た:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Warning"
message:@"Are you sure?"
delegate:self
cancelButtonTitle:@"NO"
otherButtonTitles:@"YES", nil];
[alert show];
[self.array removeObjectAtIndex:indexPath.row];//or something similar to this based on your data source array structure
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:@"Nee"])
{
NSLog(@"Nothing to do here");
}
else if([title isEqualToString:@"Ja"])
{
NSLog(@"Delete the cell");
}
}
しかし、セルを右にスワイプして削除ボタンが表示された場合、AlertViewが表示されません。削除ボタンを押したときにのみAlertViewが表示されます。削除ボタンを押すとメッセージが表示されますが、セルはすでに削除されています。
これを機能させる方法は?したがって、スワイプするとAlertViewが表示されます。