ios - 线程 1 :EXC_BAD_ACCESS (code=1, 地址=0x14)

标签 ios objective-c xcode uitableview

我正在尝试创建从 TableView 中删除行的功能,这就是我的做法。错误来自

[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath] withRowAnimation:UITableViewRowAnimationFade];

任何帮助将不胜感激。谢谢!
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {


    if (editingStyle == UITableViewCellEditingStyleDelete) {

        [self.homeworkArray removeObjectAtIndex:indexPath.row];

        [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }

    [self.tableView reloadData];

}

最佳答案

arrayWithObjects:方法需要 nil终止列表,所以你需要说 -

[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationFade];
}

或者更简单,使用 arrayWithObject:
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}

或者正如@rmaddy 指出的那样,使用数组文字语法 -
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}

此外,您不需要 reloadData调用 - deleteRowsAtIndexPaths将负责更新 TableView 中的相关行。

关于ios - 线程 1 :EXC_BAD_ACCESS (code=1, 地址=0x14),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26923109/

相关文章:

iphone - 如何创建流畅的图像动画

Objective-C异常处理: "Divided by Zero Exception" is not getting caught

objective-c - Xcode 4.4 中的自动@synthesized 属性

iphone - 每次应用程序激活时加载 View

ios - 触摸单元格时更改 UITableViewCell 的附件类型

ios - 单击 UITextField 时如何显示联系人?

ios - 关于ScrollView与PageControl的几个问题

ios - 导航 Controller 标题图像消失

ios - 如何在 swift ios xcode 中播放本地容器中的音频声音文件

ios - '没有团队 'LXxxxxxxx' 的帐户'Xcode 9.4 上的构建错误