Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 从fetchedresultsController删除时出错索引处无节_Iphone_Ios_Uitableview_Core Data_Nsfetchedresultscontroller - Fatal编程技术网

Iphone 从fetchedresultsController删除时出错索引处无节

Iphone 从fetchedresultsController删除时出错索引处无节,iphone,ios,uitableview,core-data,nsfetchedresultscontroller,Iphone,Ios,Uitableview,Core Data,Nsfetchedresultscontroller,我想弄明白这一点已经有一段时间了,但还没有取得任何进展。我需要一些帮助。 我正在使用一个有2个回迁的表。只能编辑表最后一部分中的1。当我删除一个项目时,应用程序崩溃,说索引中没有节。我读过一些对其他类似问题的回答,但仍然无法解决 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return [[fetchedResultsController sections] count]+1; } - (NSI

我想弄明白这一点已经有一段时间了,但还没有取得任何进展。我需要一些帮助。
我正在使用一个有2个回迁的表。只能编辑表最后一部分中的1。当我删除一个项目时,应用程序崩溃,说索引中没有节。我读过一些对其他类似问题的回答,但仍然无法解决

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [[fetchedResultsController sections] count]+1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section < fetchedResultsController.sections.count) {
        return [[fetchedResultsController.sections objectAtIndex:section]     numberOfObjects];
    }
    else {
        return fetchedResultsControllerCustomWOD.fetchedObjects.count;
    }
}

如果我正确理解您的所有抓取控制器,则您是:

在此处删除CoreData中的对象一次:

 // Delete object from database
        [context deleteObject:[[fetchedResultsControllerCustomFR     objectAtIndexPath:indexPath] objectAtIndex:indexPath.row]];
然后保存上下文:

NSError *error = nil;
if (![context save:&error]) {
    NSLog(@"Can't Delete! %@ %@", error, [error localizedDescription]);
    return;
}
这反过来会提醒
fetchedResultsControllerCustomFR
某个项目已被删除

然后再次尝试从
fetchedResultsControllerCustomFR
中删除:

// Remove device from table view
        [[fetchedResultsControllerCustomFR objectAtIndexPath:indexPath]     removeObjectAtIndex:indexPath.row];
他们应该已经知道它不见了。假设您已经设置了fetch controller委托

编辑:

在-begin和-end调用中包装删除调用:

[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
[tableView endUpdates];

最后一个应该被注释掉。。。但即使我这样做了,我也得到:**由于未捕获的异常而终止应用程序'NSInternalInconsistencyException',原因:'索引14处没有部分'感谢更新的响应,但它再次崩溃。这是控制台日志:**-[UITableView\u endCellAnimationsWithContext:]、/SourceCache/UIKit\u Sim/UIKit-2380.17/UITableView.m:1070此外,我启用了objc\u异常抛出,其输出为:libobjc.A.dylib`objc\u异常抛出:0x2547e52:pushl%ebp,如果有帮助的话。
[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
[tableView endUpdates];