NSFetchedResultsController在辅助UITableView - 如何查询数据? [英] NSFetchedResultsController on secondary UITableView - how to query data?
问题描述
我创建了一个基于核心数据的导航iPhone应用程序与多个屏幕。让我们说它是一个闪存卡应用程序。数据模型非常简单,只有两个实体:Language和CardSet。在Language实体和CardSet实体之间存在一对多关系,因此每个语言可以包含多个CardSet。换句话说,Language有一个一对多关系,指向CardSets列表的Language.cardSets,CardSet有一个指向语言的CardSet.language关系。
I am creating a core-data based Navigation iPhone app with multiple screens. Let's say it is a flash-card application. The data model is very simple, with only two entities: Language, and CardSet. There is a one-to-many relationship between the Language entity and the CardSet entities, so each Language may contain multiple CardSets. In other words, Language has a one-to-many relationship Language.cardSets which points to the list of CardSets, and CardSet has a relationship CardSet.language which points to the Language.
有两个屏幕:(1)初始的TableView屏幕,显示语言列表;
There are two screens: (1) An initial TableView screen, which displays the list of languages; and (2) a secondary TableView screen, which displays the list of CardSets in the Language.
在初始屏幕中,其中列出了语言,我使用NSFetchedResultsController来保持最新的语言列表。屏幕将选择的语言传递到辅助屏幕。
In the initial screen, which lists the languages, I am using NSFetchedResultsController to keep the list of languages up-to-date. The screen passes the Language selected to the secondary screen.
在辅助屏幕上,我试图找出是否应该再次使用NSFetchedResultsController来维护CardSets列表,或者如果我应该通过Language.cardSets工作,简单地拉出对象模型中的列表。后者是最有意义的程序,因为我已经有语言 - 但是它不会自动更新更改。
On the secondary screen, I am trying to figure out whether I should again use an NSFetchedResultsController to maintain the list of CardSets, or if I should work through Language.cardSets to simply pull the list out of the object model. The latter makes the most sense programatically because I already have the Language - but then it would not automatically be updated on changes.
我看过NSFetchedResultsController文档,似乎我可以根据属性轻松创建谓词 - 但不是关系。也就是说,我可以创建以下NSFetchedResultsController:
I have looked at the NSFetchedResultsController documentation, and it seems like I can easily create predicates based on attributes - but not relationships. I.e., I can create the following NSFetchedResultsController:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name LIKE[c] 'Chuck Norris'"];
如何通过直接关系访问我的数据 - Language.cardSets - - 更新使用NSFetchedResultsController?这是可能的吗?
How can I access my data through the direct relationship - Language.cardSets - and also have the table auto-update using NSFetchedResultsController? Is this possible?
推荐答案
如果在细节中使用 NSFetchedResultsController
你会得到自动通知任何更改的集合是一个净胜。为了方便起见,我个人会使用第二个 NSFetchedResultsController
。
If you use a NSFetchedResultsController
in the detail you get automatic notification of any changes to the set which is a net win. Personally I would use a second NSFetchedResultsController
just for its convenience.
这篇关于NSFetchedResultsController在辅助UITableView - 如何查询数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!