Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.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
Objective c 删除节中的最后一行->;崩溃,使用NSFetchedResultsController_Objective C_Xcode_Ios5_Nsfetchedresultscontroller - Fatal编程技术网

Objective c 删除节中的最后一行->;崩溃,使用NSFetchedResultsController

Objective c 删除节中的最后一行->;崩溃,使用NSFetchedResultsController,objective-c,xcode,ios5,nsfetchedresultscontroller,Objective C,Xcode,Ios5,Nsfetchedresultscontroller,我正在使用NSFetchedResultsController。以前我遇到过一个类似的问题,当数据库没有tableview的条目时,但是创建了一个条目,我发现必须至少有一个部分,所以我修复了这个问题。但现在它崩溃了,比如我有两个部分,每个部分有一行,我删除了一行,所以部分应该消失了->崩溃。它表示更新之前的节数(2)不等于删除的节数(0) 我发现了问题/解决方案: 对于这种情况,我没有所需的didChangeSection委托方法 - (void)controller:(NSFetchedRes

我正在使用NSFetchedResultsController。以前我遇到过一个类似的问题,当数据库没有tableview的条目时,但是创建了一个条目,我发现必须至少有一个部分,所以我修复了这个问题。但现在它崩溃了,比如我有两个部分,每个部分有一行,我删除了一行,所以部分应该消失了->崩溃。它表示更新之前的节数(2)不等于删除的节数(0)


我发现了问题/解决方案:

对于这种情况,我没有所需的didChangeSection委托方法

- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo
           atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type {
NSLog(@"didChangeSection");

    switch(type) {
        case NSFetchedResultsChangeInsert:
            [self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
            break;

        case NSFetchedResultsChangeDelete:
            [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
            break;
    }
}
-(void)控制器:(NSFetchedResultsController*)控制器didChangeSection:(id)sectionInfo
atIndex:(nsInteger)ChangeType:(NSFetchedResultsChangeType)类型的节索引{
NSLog(“didChangeSection”);
开关(类型){
案例NSFetchedResultsChangesInsert:
[self.tableView insertSections:[NSIndexSet IndexSetWithiIndex:sectionIndex]带RowAnimation:UITableViewRowAnimationFade];
打破
案例NSFetchedResultsChangeDelete:
[self.tableView deleteSections:[NSIndexSet IndexSetWithiIndex:sectionIndex]带RowAnimation:UITableViewRowAnimationFade];
打破
}
}

我也有同样的问题。然而,仅仅实现controller:didchangessection:atIndex:forChangeType方法并没有修复我的崩溃。我要做的是在一个原子更新中实现多个表视图更新(节删除+将行从刚删除的节移动到现有或新的节)。我只是补充说:

- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller
{
    [self.tableView beginUpdates];
}

- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller
{
    [self.tableView endUpdates];
}

这行是怎么回事:return[[fetchedResultsController节]count]?:1.您缺少中间的参数。我认为您实际上缺少了第一个参数,并且将它们放在了错误的位置。这看起来很奇怪,但实际上是正确的:)这是返回[[fetchedResultsController sections]计数]>0的简写版本?[[fetchedResultsController节]计数]:1;我发现,该消息通常意味着在您实际获取消息以执行删除/删除的方法中出现了问题。从你的帖子看来,你实际上并没有改变它的节数?也许还可以发布您用于删除节的代码?好的,我用您询问的方法更新了我的帖子。这看起来很正确,有两个后续问题1)调用代码时您确定fetchedResultsController存在,对吗?我知道这听起来有点傻,但我想核实一下。然后2)如果您正在使用表的值人工更改节计数,而不是仅使用“[[fetchedResultsController节]计数]”作为节数的返回值,那么是否确实有对象传递给“deleteObject:”?
- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo
           atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type {
NSLog(@"didChangeSection");

    switch(type) {
        case NSFetchedResultsChangeInsert:
            [self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
            break;

        case NSFetchedResultsChangeDelete:
            [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
            break;
    }
}
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller
{
    [self.tableView beginUpdates];
}

- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller
{
    [self.tableView endUpdates];
}