Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 通过警报确认删除UITableViewController中的行_Objective C_Ios - Fatal编程技术网

Objective c 通过警报确认删除UITableViewController中的行

Objective c 通过警报确认删除UITableViewController中的行,objective-c,ios,Objective C,Ios,我有一个UITableViewController,设置为用户可以删除行。这是我的delete操作处理程序代码,以及UIAlertView的委托方法: - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == U

我有一个
UITableViewController
,设置为用户可以删除行。这是我的delete操作处理程序代码,以及
UIAlertView
的委托方法:

- (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];
    }
}
问题在于最后一行,它实际上应该从
表视图
中删除行。如果我把它(以及从数据源删除的代码)放在第一个方法中,而不是放在
UIAlertView
的东西中,它就可以正常工作


这样做的正确方法是什么?

问题是
UIIndexPath
对象在该方法中是错误的!我猜这是因为在显示警报视图时没有选择行。因此,在执行
UIAlertView
代码之前,我将其保存到视图控制器类的属性中,并在稍后的第二个方法中检索到它,它工作正常。

问题在于
UIIndexPath
对象在该方法中是错误的!我猜这是因为在显示警报视图时没有选择行。因此,在执行
UIAlertView
代码之前,我将其保存到视图控制器类的属性中,并在稍后的第二个方法中检索到它,它工作正常