核心数据:NSFetchedResultsController 可以获取两个不同的实体吗? [英] Core data: can NSFetchedResultsController fetch two different entities?

查看:35
本文介绍了核心数据:NSFetchedResultsController 可以获取两个不同的实体吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 iPhone 应用程序,在一个特定的视图中,我需要加载两个不同的实体:一个将填充 UITableView,另一个将填充 UITextView.

I am working on an iPhone app, and in a particular view I need to load two different entities: One that will populate a UITableView, and another that will populate a UITextView.

是否可以使用单个 NSFetchedResultsController 获取这两个属性?

Is it possible to fetch both properties using a single NSFetchedResultsController?

或者我需要使用两个不同的 NSFetchedResultsController 吗?

Or do I need to use two different NSFetchedResultsControllers?

关于如何最好地解决这个问题的任何想法?

Any ideas on how to best approach this problem?

推荐答案

每个 fetch 请求只有一个实体,每个 fetched results 控制器只有一个 fetch.因此,您需要为每个实体使用单独的控制器.

Each fetch request has only one entity and each fetched results controller has only one fetch. Therefore, you need separate controllers for each entity.

如果您考虑一下,您将如何创建谓词来获取两个逻辑上独立的实体?

If you think about it, how would you make a predicate to fetch two logically separate entities?

您可能根本不需要两次提取.在大多数情况下,您可以获取填充表格的实体,然后使用所选行的实体的关系来填充文本视图之类的内容.

You probably don't need two fetches at all. In most cases, you can fetch the entities that populate the table and then use a relationship for the entity of the selected row to populate something like a text view.

这篇关于核心数据:NSFetchedResultsController 可以获取两个不同的实体吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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