Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.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管理并在第一节中有1个额外单元格的UITableView_Objective C_Uitableview_Core Data_Nsfetchedresultscontroller - Fatal编程技术网

Objective c 正在更新由NSFetchedResultsController管理并在第一节中有1个额外单元格的UITableView

Objective c 正在更新由NSFetchedResultsController管理并在第一节中有1个额外单元格的UITableView,objective-c,uitableview,core-data,nsfetchedresultscontroller,Objective C,Uitableview,Core Data,Nsfetchedresultscontroller,主细节应用程序- 我有一个UITableViewController,它由nsfetchedresultscoontroller及其委托方法管理。在tableview的第一部分,我还有一个额外的单元格,其中有一个UIWebView,用于显示嵌入式视频。此单元格不是NSFetchedResultsController的一部分。调用-tableView-cellforrowatinexpath时,我将其添加到IF语句中,该语句检查它是否是第一节和第一行。大多数情况下,一切都很好。我可以选择一行并将其

主细节应用程序-

我有一个
UITableViewController
,它由
nsfetchedresultscoontroller
及其委托方法管理。在tableview的第一部分,我还有一个额外的单元格,其中有一个
UIWebView
,用于显示嵌入式视频。此单元格不是NSFetchedResultsController的一部分。调用
-tableView-cellforrowatinexpath
时,我将其添加到
IF
语句中,该语句检查它是否是第一节和第一行。大多数情况下,一切都很好。我可以选择一行并将其显示在
DetailViewController
中,我可以从
tableView
中删除项目,我可以更改
DetailViewController
中的信息,并且
tableViewCell
标签更新没有任何问题

我的问题

我唯一一次对它的设置方式有问题是,当我从
表视图的第一部分删除最后一个对象时

错误

CoreData:错误:严重的应用程序错误。发现了一个异常 在调用时从NSFetchedResultsController的委托 -controllerDidChangeContent:。无效更新:节0中的行数无效。现有节中包含的行数 更新后(3)必须等于中包含的行数 更新前的那一部分(2),加上或减去行数 从该节插入或删除(0插入,0删除)以及 或减去移入或移出该节的行数(0) 在中,0已移出)。带userInfo(空)

代码

行数部分

这是我检查视频是否可用的地方,如果部分为0,则返回额外的一行。否则从
NSFetchedResultsController
返回对象计数。我想这就是我的问题所在。然而,我不知道如何修复它。因为我使用了
NSFetchedResultsController
委托方法来管理它,所以在switch语句的“type”内部有什么我可以做的吗

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0 && self.videoInfoReceived == YES) {
        id <NSFetchedResultsSectionInfo> secInfo = [[self.fetchedResultsController sections] objectAtIndex:section];
        return [secInfo numberOfObjects] + 1;
    } else {
        id <NSFetchedResultsSectionInfo> secInfo = [[self.fetchedResultsController sections] objectAtIndex:section];
        return [secInfo numberOfObjects];
    }

}
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节
{
如果(节==0&&self.videoinformeceived==YES){
id secInfo=[[self.fetchedResultsController节]objectAtIndex:section];
返回[secInfo numberOfObjects]+1;
}否则{
id secInfo=[[self.fetchedResultsController节]objectAtIndex:section];
返回[secInfo numberOfObjects];
}
}
NSFetchedResultsController委托

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

- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo
           atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type
{
    switch(type) {
        case NSFetchedResultsChangeInsert:
            [self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
            NSLog(@"didChangeSection - ChangeInsert");
            break;

        case NSFetchedResultsChangeDelete:
            [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
            NSLog(@"didChangeSection - ChangeDelete");
            break;
    }
}

- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
       atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
      newIndexPath:(NSIndexPath *)newIndexPath
{
    UITableView *tableView = self.tableView;

    switch(type) {
        case NSFetchedResultsChangeInsert:
            [tableView insertRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
            NSLog(@"didChangeObject - ChangeInsert");
            break;

        case NSFetchedResultsChangeDelete:
            [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
            NSLog(@"didChangeObject - ChangeDelete");
            break;

        case NSFetchedResultsChangeUpdate:
            [self configureCell:[tableView cellForRowAtIndexPath:indexPath] atIndexPath:indexPath];
            NSLog(@"didChangeObject - ChangeUpdate");
            break;

        case NSFetchedResultsChangeMove:
            [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
            [tableView insertRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
            NSLog(@"didChangeObject - ChangeMove");
            break;
    }
}

- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller
{
    [self.tableView endUpdates];
}
-(void)controllerWillChangeContent:(NSFetchedResultsController*)控制器
{
[self.tableView开始更新];
}
-(void)控制器:(NSFetchedResultsController*)控制器didChangeSection:(id)sectionInfo
atIndex:(nsInteger)ChangeType:(NSFetchedResultsChangeType)类型的节索引
{
开关(类型){
案例NSFetchedResultsChangesInsert:
[self.tableView insertSections:[NSIndexSet IndexSetWithiIndex:sectionIndex]带RowAnimation:UITableViewRowAnimationFade];
NSLog(@“didChangeSection-ChangeInsert”);
打破
案例NSFetchedResultsChangeDelete:
[self.tableView deleteSections:[NSIndexSet IndexSetWithiIndex:sectionIndex]带RowAnimation:UITableViewRowAnimationFade];
NSLog(@“didChangeSection-ChangeDelete”);
打破
}
}
-(void)控制器:(NSFetchedResultsController*)控制器didChangeObject:(id)一个对象
atIndexPath:(NSIndexPath*)indexPath forChangeType:(NSFetchedResultsChangeType)类型
newindepath:(nsindepath*)newindepath
{
UITableView*tableView=self.tableView;
开关(类型){
案例NSFetchedResultsChangesInsert:
[tableView insertRowsAtIndexPaths:@[newIndexPath]带RowAnimation:UITableViewRowAnimationFade];
NSLog(@“didChangeObject-ChangeInsert”);
打破
案例NSFetchedResultsChangeDelete:
[tableView deleteRowsAtIndexPaths:@[indexPath]和RowAnimation:UITableViewRowAnimationFade];
NSLog(@“didChangeObject-ChangeDelete”);
打破
案例NSFetchedResultsChangeUpdate:
[self-configureCell:[tableView cellForRowAtIndexPath:indexPath]atIndexPath:indexPath];
NSLog(@“didChangeObject-ChangeUpdate”);
打破
案例NSFetchedResultsChangeMove:
[tableView deleteRowsAtIndexPaths:@[indexPath]和RowAnimation:UITableViewRowAnimationFade];
[tableView insertRowsAtIndexPaths:@[newIndexPath]带RowAnimation:UITableViewRowAnimationFade];
NSLog(@“didChangeObject-ChangeMove”);
打破
}
}
-(void)controllerDidChangeContent:(NSFetchedResultsController*)控制器
{
[self.tableView endUpdates];
}

您在问题中陈述:

当我从tableView的第一个部分删除最后一个对象时

这将导致我期望例外情况说明以下内容(重点补充):

CoreData:错误:严重的应用程序错误。在调用-controllerDidChangeContent:期间,从NSFetchedResultsController的委托捕获到异常。无效更新:节0中的行数无效。更新(0)后现有节中包含的行数必须等于更新(1)前该节中包含的行数,加上或减去从该节插入或删除的行数(0插入,1删除)加上或减去移入或移出该节的行数(0移入,0移出)。带userInfo(空)

因为异常声明行计数从2增加到3,而没有