NSFetchResults 更新委托第一次工作,第二次崩溃
我环顾四周寻找类似的答案,但我的问题似乎有点不同。
我有一个与 NSFetchResultsController 绑定的 UITableView。目标是提取一些数据,将几行添加到上下文中,然后表会自动更新。很简单,对吧? 初始化->空表->执行Fetch ->在 Context 中创建一些对象 ->代表看到这一点并更新我的表格。
我使用样板 NSFetchResultsController 来通知当前上下文何时被修改。
当我使用干净的模拟器/iOS 平台运行此程序时,NSFetchController 成功识别出上下文中的数据已更新。但是,如果我第二次运行该应用程序,则会收到以下错误:
CoreData: error: Serious application error. Exception was caught during Core Data change
processing. This is usually a bug within an observer of
NSManagedObjectContextObjectsDidChangeNotification. *** -[__NSArrayI objectAtIndex:]:
index 40 beyond bounds for empty array with userInfo (null)
调用 [self.tableView beginUpdates]; 时发生崩溃;
在我的调试中,我可以看到“[fetchedResultsController fetchedObjects]”完全是空的,我认为这就是问题所在 - 自从我修改了上下文后,这不应该用我的测试数据进行更新吗?我使用 Apple Recipe 和 CoreDataBooks 示例作为参考。
I've looked around SO for similar answers, but my issue seems a litte different.
I have a UITableView that is tied to a NSFetchResultsController. The goal is to pull up some data, add a couple rows into the Context, and the table is automatically updated. Simple, right?
init -> empty table -> performFetch -> create some objects in the Context -> delegate sees this and updates my table.
I'm using the boilerplate NSFetchResultsController for noticing when the current context has been modified.
When I run this with a clean Simulator/iOS platform, the NSFetchController successfully recognizes that data in the Context has been updated. But if I run the app a second time, I get the following error:
CoreData: error: Serious application error. Exception was caught during Core Data change
processing. This is usually a bug within an observer of
NSManagedObjectContextObjectsDidChangeNotification. *** -[__NSArrayI objectAtIndex:]:
index 40 beyond bounds for empty array with userInfo (null)
The crash occurs on calling [self.tableView beginUpdates];
In my debugging I can see that '[fetchedResultsController fetchedObjects]' is completely empty and I think thats the problem - shouldn't this be updating with my test data since I modified the context? I'm using the Apple Recipe and CoreDataBooks examples as reference.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这是因为类中的数据模块不适合 .xcdatamodeld 文件中的实体。
I think this is because you Data Modle in class just not fit the entity in you .xcdatamodeld file.