0

好的,我最近按照教程来实现 NSFetchedResultController 它工作得很好!我还发现了一个关于如何删除行的问题。我将建议的代码行添加到我的实现文件中。

当您向左滑动并按下删除按钮时,没有任何反应。没有错误,没有删除行,也没有崩溃。

这是我的代码

    // Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [self.managedObjectContext deleteObject:[self.fetchedResultsController objectAtIndexPath:indexPath]];

        NSError *error = nil;
        if (![self.managedObjectContext save:&error]) {
            // handle error

        }
        else if (editingStyle == UITableViewCellEditingStyleInsert) {
            // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
        }   
    }
}

我可能做错了什么?

4

1 回答 1

0

我想通了,我有;

 [self.managedObjectContext deleteObject:[self.fetchedResultsController objectAtIndexPath:indexPath]];

它必须是

[context deleteObject:[self.fetchedResultsController objectAtIndexPath:indexPath]]; Thank you very much for your response! 
于 2013-10-30T06:58:06.223 回答