NSFetchedResultsController 结果过滤
有没有一种简单的方法来过滤 NSFetchedResultsController 提供的结果?
我使用的是标准核心数据模板,它非常适合简单的表格。
我拥有的是一个 UITableVIew
,其中一个 UISegmentedControl
有两个类别,一个显示所有类别,另一个类别在选择时应仅显示今天创建的事件。
我已经能够在两个不同的 tableView 中完成此任务(所以我知道如何使用 NSPredicate,这不是我的问题;问题是将其组合到单个 tableView 中)。
我知道一旦创建了 NSFetchedResultsController 就无法更改 fetchRequest 。
所以我猜我必须创建一个新的 NSFetchedResultsController 。
有没有人实施过类似的事情或者对如何实现这一点有任何想法?
Is there an easy way to filter the results provided by the NSFetchedResultsController
?
I am using the standard Core Data Template which works very well for simple tables.
What I have is a UITableVIew
with a UISegmentedControl
with two categories, one that displays all and one that when selected should display only events what were created today.
I have been able to accomplish this in two different tableViews (so i know how to use NSPredicate, that is not my problem; the problem is combining it into a single tableView).
I know you cannot change the fetchRequest once the NSFetchedResultsController
has been created.
So I can guess that I will have to create a new NSFetchedResultsController
.
Has anyone implemented something like this or have any ideas on how to accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,您必须创建一个新的 NSFetchedResultsController - 毕竟,更改获取请求基本上相当于从头开始重新初始化它(由于
NSFetchedResultsController
在后台执行的操作) -所获取数据的场景)。Yes, you must create a new
NSFetchedResultsController
– after all, changing the fetch request would basically amount to reinitializing it from scratch anyways (due to the operations thatNSFetchedResultsController
performs behind-the-scenes on the fetched data).我没有像我的代码库那样使用 NSFetchedResultsController ,但是在过去,我刚刚根据分段控制的状态使用不同的谓词发出了 NSFetechedResults 请求。
I haven't used NSFetchedResultsController much as my codebase predates it, however in the past i have just fired off an NSFetechedResults request with a different predicate depending on the state of the segmentedControl.