混淆从AppDelegate获取ManagedObjectContext [英] Confused in getting the ManagedObjectContext from AppDelegate

查看:441
本文介绍了混淆从AppDelegate获取ManagedObjectContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在查看关于核心数据的文档,并试图找出如何安排核心数据栈,以便它可以访问我的所有UITableViewControllers。 Apple提供的所有示例都表明这是在AppDelegate上实现的,但文档不推荐这种方法,因为它太脊了!请参阅链接

I've been looking at the documentation on Core Data and trying to figure out how to arrange the Core Data Stack so it's accessible to all of my UITableViewControllers. All the examples provided by Apple show this to be implemented on the AppDelegate yet the documentation doesn't recommend this approach because it's too ridged! See link.

(为什么不在iPhone SDK文档中提及是另一个谜)

(Why this isn't mention on the iPhone SDK documentation is another mystery)

我的问题是,我已经重复设计模式根据TopSongs中显示的Core Data示例检索子表视图的ManagedObjectContext实体,并生成以下错误...找不到实体名称的NSManagedObjectModel '歌曲'。奇怪的是,这可以在父表视图上找到它,所以我认为它是因为AppDelegate上的Core数据堆栈已经是dealoc。

My problem is that I've repeated the design pattern as per the Core Data example shown in TopSongs to retrieve a ManagedObjectContext Entity for a child Table View and the following error is produced… could not locate an NSManagedObjectModel for entity name 'Song'. Strangely this can be found it on the parent Table View so I presume it's because the Core Data stack on the AppDelegate has been dealoc.

有没有人知道一个很好的例子,与在Recipies,CoreData Books和Locations创建的模式不同的设计模式?所有这些都遵循相同的模式。

Does anyone know a good example that follows a different design pattern to the ones created on Recipies, CoreData Books and Locations? All these follow the same pattern.

所有我想要做的是在chid表格视图中检索原始数据并使用不同的条件排序。

All I want to do is retrive the original data and sort is with a different criteria in the chid tableview.

推荐答案

对于人们喜欢将核心数据堆栈放置在这个问题。我倾向于将堆栈放在一个单例(如我在那里指示)。这可以让你方便地访问堆栈,无论你需要在你的应用程序中。

There is significant discussion about where people favor placing the Core Data stack in this question. I tend to place the stack within a singleton (as I indicate there). This gives you convenient access to the stack wherever you need it within your application.

至于你的问题,我发现你的核心数据堆栈的元素已解除分配。首先,你会崩溃发送消息到你的上下文或模型,而不是得到你现在的报告。如果你可以从应用程序中的其他地方访问Song实体,我的打赌是你没有正确地传递上下文模型到需要它的实例。

As far as your problem, I find it highly unlikely that the elements of your Core Data stack have been deallocated. For one thing, you'd be crashing on sending a message to your context or model, rather than getting back the report you are now. If you can access the "Song" entity from somewhere else in your application, my bet is that you're not passing the model ot context properly to the instance that needs it.

这篇关于混淆从AppDelegate获取ManagedObjectContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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