我是Objective-C的新手.所以我在一节(5个单元格)中有一个包含5行的表格视图,我希望允许用户删除它们,但是当我点击删除按钮时应用程序会一直崩溃.它崩溃的原因是因为我在节中有5行而不是返回[self.myListItems count]如何在保留节中的5行的同时更正下面的代码?
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[self.myListItems removeObjectAtIndex:indexPath.row];
[self saveList];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
Run Code Online (Sandbox Code Playgroud)
错误是:断言失败 - [UITableView _endCellAnimationsWithContext:]