tableView中显示的核心数据关系
我正在开发一个带有显示核心数据表内容的表格视图的应用程序。 数据模型是这样的: Entity(name, code)->>Translation(text, code)
我使用通常的 NSFetchedResultsController 检索所有实体,但随后需要填充每一行(通过 tableview cellForRowAtIndexPath:) 我必须深入到每个实体中根据用户输入的代码检索 2 个翻译。我正在使用 NSFetchRequest 来做到这一点,但我想知道这是否是正确的做法(每次填充一行时一个提取请求)。 本能地,我会检索 NSFetchedResultsController 中所需的所有数据,而不是每次填充单元格时搜索每个翻译,但我不知道如何进行。 有人有一些建议,或者一些有趣的链接吗?
I am developing an application with a tableview showing the content of a core data table.
The datamodel is something like this:
Entity(name, code)->>Translation(text, code)
I retrieve all the entities using the usual NSFetchedResultsController, but then once is time to populate each row (through tableview cellForRowAtIndexPath:) I have to dive into each entity to retrieve 2 translations based on the code inputed by the user. I am using a NSFetchRequest to do that but I was wondering if it is the right thing to do (one fetch request each time I populate a row).
Instinctively I would retrieve all the data I need in the NSFetchedResultsController, instead of searching for each translation each time I populate a cell, but I cannot figure out how.
Do anyone has some advice, or maybe some interesting links?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果每个单元格必须显示与每个实体对象相关的翻译对象,那么您只需将关系从获取的实体对象遍历到适当的翻译对象。
获取实体对象并构建表以显示它们后,然后访问每个单元格行的翻译中的值,如下所示:
...它为表视图表示的实体对象返回一组翻译对象排。
作为一个非常一般的规则,每个表视图只执行一次提取。表视图应配置为显示与一个特定实体相关的数据。
If each cell must display the Translation objects related to each Entity object, then you only need to walk the relationship from the fetched Entity object to the appropriate Translation objects.
Once you've fetched the Entity objects and then structured the table to display them, then to access the values in the translations for each cell row like so:
... which returns a set of Translation object for the Entity object represented by the tableview row.
As a very general rule, you only do one fetch per tableview. A table view should be configured to display data related to one particular entity.