核心数据、KVO 和 NSInternalInconsistencyException

发布于 2024-09-08 17:27:19 字数 838 浏览 1 评论 0原文

我正在使用 Core Data 和 KVO 来查找值的更改以触发保存到数据存储。我有一个表视图,其搜索连接到 NSFetchedResultsController。当搜索发生变化时,按下“搜索”按钮就会创建一个新的结果控制器。当用户在结果表视图中选择一个项目时,用户将进入详细视图并可以进行编辑。

这就是我遇到问题的地方。当用户在我所做的单独 UIControl 中进行更改时,详细信息视图会收到通知,并且可以使用它记住的 NSFetchedResultsController ,从表视图将我推到视图堆栈上以获取 NSManagedObjectContext 并进行保存。当我这样做时,有时会出现以下错误:

Serious application error.  Exception was caught during Core Data change processing.  This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification.  no object at index 89 in section at index 0 with userInfo (null)
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'no object at index 89 in section at index 0'

我发现当我进行搜索并且不在表格顶部的对象被移到顶部时,往往会发生这种情况。我隐约知道我的脑子里可能出了什么问题,但希望能得到任何关于如何解决这个问题的指示。

I'm using Core Data and KVO to look for changes in values to trigger saves to the data store. I have a table view with search hooked up to NSFetchedResultsController. When the search changes, a new results controller is made on pressing the Search button. When the user selects an item in the results table view, then the user enters a detail view and can make edits.

This is where I encounter the problems. When the user makes a change in a separate UIControl that I made, the detail view is notified and can use the NSFetchedResultsController it remembers from when the table view pushed me onto the view stack to get the NSManagedObjectContext and do a save. When I do so, I sometimes get the following error:

Serious application error.  Exception was caught during Core Data change processing.  This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification.  no object at index 89 in section at index 0 with userInfo (null)
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'no object at index 89 in section at index 0'

I found that this tends to happen when I do a search and an object that isn't on the top of the table is moved up to the top. I vaguely know what might be wrong in the back of my head, but would appreciate any pointers as to how to fix this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乙白 2024-09-15 17:27:19

我知道出了什么问题了。我忘记取消设置旧的 NSFetchedResultsController 委托,也忘记释放所述 NSFetchedResultsController。我的 UITableView 子类还通过委托响应对 NSFetchedResultsController 的更新,并导致进行奇怪的调用。

I figured out what was wrong. I forgot to unset the old NSFetchedResultsController's delegate, and also forgot to release said NSFetchedResultsController. My UITableView subclass also responded to updates to the NSFetchedResultsController through delegates, and caused weird calls to be made.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文