无法删除 TableView 中的某些行

Cannot delete more than some rows in TableView

我可以删除一些行,但在某些时候,我不能再删除了。我可以删除的第一个行数是随机的。

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete)
    {
        //add code here for when you hit delete
        [detailProductArray removeObjectAtIndex:indexPath.row];
        [detailTableView reloadData];
    }
}

你们中有人有想法吗?

我想将您引导至此处以获取有关删除和添加行的完整答案。 Add/Delete UITableViewCell with animation?

UITableviewView 可以使用以下方法以动画方式添加和删除行。

[tableView beginUpdates];
[tableView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationFade];
[tableView deleteRowsAtIndexPaths:deleteIndexPaths withRowAnimation:UITableViewRowAnimationFade];
[tableView endUpdates];

我的最终代码:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete)
    {
        //add code here for when you hit delete
        [detailProductArray removeObjectAtIndex:indexPath.row];
        [DetailTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
    }
}