ios - 在模型层过滤 NSFetchedResultsController

标签 ios objective-c core-data nsfetchedresultscontroller

我需要帮助来考虑和实现 NSFetchedResultsControllerfetchedObjects 在模型层的过滤。

文档说:

Responding to Changes

In general, NSFetchedResultsController is designed to respond to changes at the model layer, by informing its delegate when result objects change location or when sections are modified.

NSFetchedResultsController Class Reference

例如,如何在模型层实现搜索?

我想象一个 Filter 实体,它以某种方式与被过滤的实体相关,并在 NSFetchRequest 的谓词中使用。

也许我会创建一个 Filter 对象,用搜索字段中的字符串来配置它,然后保存该对象。这将影响 NSFetchRequest 的谓词,因此 NSFetchedResultsController 将获取用于更新其 fetchedObjects 的私有(private)消息并向其委托(delegate)发出消息。

我可以创建其他 Filter 对象(或更改现有对象),这会进一步影响 NSFetchedResultsControllerfetchedObjects,并且在删除时,停止影响 fetchedObjects,然后它们再次“可见”。

  • 模型在 Xcode 的模型编辑器中会是什么样子?
  • NSFetchRequest 的谓词会是什么样子?
  • 这种方法有什么缺点?

最佳答案

同意韦恩的观点。模型层不是在搜索时更新列表的合适机制。

相反,修改 NSFetchedResultsControllerfetchRequestpredicate 并重新获取。这是使用 UITableView 实现搜索的常见模式。

关于ios - 在模型层过滤 NSFetchedResultsController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32710633/

相关文章:

ios - 为什么-stringWithContentsOfURL : returning nil for my JSON communication here?

ios - PKAddPassesViewController 取消动画不起作用

iphone - AVPlayer 反向播放

swift - Swift 2.0 中的 countForFetchRequest

iOS:删除 UItableviewCell 时出错:-[UITableView _endCellAnimationsWithContext:] 中的断言失败

ios - self.fetchedResultsController 抛出 EXC_BAD_ACCESS 而 _fetchedResultsController 工作正常

ios - 遍历数组并从 JSON 文件中提取数据

ios - 当触地按钮( subview )时,不要处理 super View 上的平移手势

objective-c - ld : framework not found GData

ios - 将流字节转换为字符串