线程 1:EXC_BAD_ACCESS(代码=1,地址=0x14)
问题描述:
我正在尝试创建从 tableview 中删除行的功能,这就是我做到的.错误来自
I'm trying to create the capability of deleting rows from a tableview and this is how I did it. The error is coming from the
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath] withRowAnimation:UITableViewRowAnimationFade];
非常感谢任何帮助.谢谢!
Any help would be very much appreciated. Thank you!
-(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
来终止列表,所以你需要说 -
the arrayWithObjects:
method requires a nil
to terminate the list, so you need to say -
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationFade];
}
或者更简单,使用 arrayWithObject:
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
或者如@rmaddy 指出的那样,使用数组字面量语法 -
Or as @rmaddy points out, use array literal syntax -
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
此外,您不需要 reloadData
调用 - deleteRowsAtIndexPaths
将负责更新表视图中的相关行.
Also, you don't need the reloadData
call - deleteRowsAtIndexPaths
will take care of updating the relevant rows in the table view.