Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/104.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
Ios 更新CoreData和UINavigationController堆栈_Ios_Core Data_Uinavigationcontroller_Nsfetchedresultscontroller - Fatal编程技术网

Ios 更新CoreData和UINavigationController堆栈

Ios 更新CoreData和UINavigationController堆栈,ios,core-data,uinavigationcontroller,nsfetchedresultscontroller,Ios,Core Data,Uinavigationcontroller,Nsfetchedresultscontroller,我有一个故事板,看起来像这样: 摘要列表->递归表视图->项目视图 它是由一个导航控制器管理的,最好的部分工作良好,正如我所期望的那样。我可以编辑摘要列表中没有问题的数据: Summary List -> Recursive Table View -> Item View | | <- (make a change here, use beginUpdate and endUpdate) | Core Data 完整的错误是经典的“你做错了”: CoreData:

我有一个故事板,看起来像这样:

摘要列表->递归表视图->项目视图

它是由一个导航控制器管理的,最好的部分工作良好,正如我所期望的那样。我可以编辑摘要列表中没有问题的数据:

Summary List -> Recursive Table View -> Item View
  |
  | <- (make a change here, use beginUpdate and endUpdate)
  |
Core Data
完整的错误是经典的“你做错了”:

CoreData: error: Serious application error.  An exception was
caught from the delegate of NSFetchedResultsController during a call
to -controllerDidChangeContent:
Invalid update: invalid number of rows in section 1.
The number of rows contained in an existing section after the update
(0) must be equal to the number of rows contained in that section
before the update (1), plus or minus the number of rows inserted or 
deleted from that section (0 inserted, 0 deleted) and plus or minus
the number of rows moved into or out of that section (0 moved in, 0 moved out).

您需要实现获取的结果控制器委托方法。在委托回调中,确保删除并添加适当数量的单元格和节。那么这个错误肯定会消失

如果您以标准方式使用“获取结果”控制器设置了表,那么我很确定表是否在屏幕上并不重要。听起来好像正在进行一些不寻常的更新,或者您没有正确地将“获取结果”控制器用作数据源

如果遇到问题,可以通过将“获取结果”控制器的委托设置为
nil
来关闭跟踪。当视图离开屏幕时尝试此操作,当视图返回时恢复(并重新加载表)


请注意,您看到的异常不是由于缺少begin和endUpdates调用造成的。如果他们不见了,你就不会有例外。它们正在发生,但在其中,插入/删除和最终行计数之间不匹配。在开始更新之前,您在第1节中有一行,在不更新之后,在更新期间,您不删除任何内容

你能给出错误的全文吗?现在添加,但这只是正常的一个…细节很重要。行数、节数和计数以及操作类型都有助于诊断发生了什么。因此,它认为某个项已从表视图的第1节(第二节)中删除。你知道这是哪一个吗?为什么某个项目会从此部分中消失?你的代码的哪一部分可能在这里负责?我知道为什么它被删除了-我不知道的是如何告诉屏幕外的视图控制器为更新做准备。不,不是那样的。直接更新数据是有效的,因为我实现了begin和end更新方法。出现此问题的原因是,当我更改核心数据时,视图控制器在堆栈上仍处于活动状态-如何告知未处于活动状态的视图控制器您正在启动更新?在
视图中将出现
中处理它。只需在视图显示之前重新加载即可。因此,这里有一件稍微奇怪的事情-如果我在viewDidDissapear/中同时使用begin/end,那么它就会中断,如果我在Display中使用end,那么它就会工作:-/没有必要执行begin/end。它们只用于动画。视图不在屏幕上,因此您不需要动画。如果我不按照前面所述执行“结束”,则会出现异常。谢谢,我将尝试按照您的建议将代理设置为零,但是,我可以明确地告诉您,我没有调用beginUpdate和endUpdate-我将尝试更新问题以提供更多澄清。如果您使用的是“获取结果”控制器,那么您确实应该使用“开始更新”和“结束更新”。你在FRC委托方法中做什么?但我应该在什么时候?当初始视图控制器消失时?这里有一件稍微奇怪的事情-如果我在viewDidDissapear中同时使用begin/end/WillExample,那么它就会中断,如果我只使用end-in-Example,那么它就会工作:-/标记为answer,因为这肯定是我成功的原因!
CoreData: error: Serious application error.  An exception was
caught from the delegate of NSFetchedResultsController during a call
to -controllerDidChangeContent:
Invalid update: invalid number of rows in section 1.
The number of rows contained in an existing section after the update
(0) must be equal to the number of rows contained in that section
before the update (1), plus or minus the number of rows inserted or 
deleted from that section (0 inserted, 0 deleted) and plus or minus
the number of rows moved into or out of that section (0 moved in, 0 moved out).