NSFetchedResultsController崩溃 [英] NSFetchedResultsController Crash

查看:129
本文介绍了NSFetchedResultsController崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下步骤导致NSFetchedResultsController中的崩溃。

Following steps result in a crash in NSFetchedResultsController.


  1. 我尝试将第一个元素添加到支持NSFetchedResultsController的TableView中。


  2. 在添加工作表(模态视图控制器)上,我按取消按钮放弃新的元素。

  3. 在CancelAction回调的Cancel按钮,我删除了我创建的新临时对象。

  4. 到这里的代码与Core Data的Apple示例代码完全相似。我只有一个额外的代码是在添加工作表被关闭后调用[tableView reloadData]。

  5. 崩溃结果只有当我尝试添加第一个元素,因为它是相关的NSFetchedResultsController中的错误节数。

  1. I try to add the first element to a NSFetchedResultsController backed TableView.
  2. I create a temporary MO object and display a Modal View pane to add new object.
  3. On the Add Sheet (a Modal View Controller), I press Cancel Button to discard the new element.
  4. In the CancelAction callback for Cancel button, I delete the new temporary object I created.
  5. The code till here is exactly similar to Apple sample code for Core Data. The only extra code I have is a call to [tableView reloadData] after the Add sheet is dismissed.
  6. The crash results only if I try to add the first element, since it is related to wrong section count in NSFetchedResultsController.

这会导致以下崩溃。如果我删除冗余调用reloadData,崩溃是不可见的。

This results in a crash given below. If I remove redundant call to reloadData, the crash is not visible. If I add a reloadData call to Recipe sample code data, the crash happens there as well.

这是NSFetchedResultsController的一个已知问题吗?

Is it a known problem with NSFetchedResultsController?

2009-09-13 18:22:45.600配方[14926:20b] *由于未捕获异常NSRangeException终止应用程序,原因:'* - [NSCFArray objectAtIndex: ]:index(0)超出边界(0)'

2009-09-13 18:22:45.600 Recipes[14926:20b] * Terminating app due to uncaught exception 'NSRangeException', reason: '* -[NSCFArray objectAtIndex:]: index (0) beyond bounds (0)'

推荐答案

你自己发现,你不应该使用[tableView reloadData ],因为您可能使用了NSFetchedResultsController委托方法

As you discovered by yourself, you should NOT use [tableView reloadData], because you are probably using the NSFetchedResultsController delegate methods

– controllerWillChangeContent:
– controller:didChangeObject:atIndexPath:forChangeType:newIndexPath:
– controller:didChangeSection:atIndex:forChangeType:
– controllerDidChangeContent:

当您添加,删除或修改对象时,这些方法实际上负责更新表视图。因此,当您添加对[tableView reloadData]的调用时,会发生什么是两个不同的线程都访问/修改您的表视图。这会导致您遇到崩溃。

These methods are actually in charge of updating your table view when you add, delete or modify objects. Therefore, when you add the call to [tableView reloadData] what happens is that two different threads are both accessing/modifying your table view. This causes the crash you are experiencing.

如果您没有使用委托方法,那么崩溃是由于代码中的其他原因。

If you are not using the delegate methods, then the crash is due to something else in your code.

这篇关于NSFetchedResultsController崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆