我需要帮助来考虑和实现 NSFetchedResultsController
的 fetchedObjects
在模型层的过滤。
文档说:
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.
例如,如何在模型层实现搜索?
我想象一个 Filter
实体,它以某种方式与被过滤的实体相关,并在 NSFetchRequest
的谓词中使用。
也许我会创建一个 Filter
对象,用搜索字段中的字符串来配置它,然后保存该对象。这将影响 NSFetchRequest
的谓词,因此 NSFetchedResultsController
将获取用于更新其 fetchedObjects
的私有(private)消息并向其委托(delegate)发出消息。
我可以创建其他 Filter
对象(或更改现有对象),这会进一步影响 NSFetchedResultsController
的 fetchedObjects
,并且在删除时,停止影响 fetchedObjects
,然后它们再次“可见”。
- 模型在 Xcode 的模型编辑器中会是什么样子?
NSFetchRequest
的谓词会是什么样子?- 这种方法有什么缺点?
最佳答案
同意韦恩的观点。模型层不是在搜索时更新列表的合适机制。
相反,修改 NSFetchedResultsController
的 fetchRequest
的 predicate
并重新获取。这是使用 UITableView
实现搜索的常见模式。
关于ios - 在模型层过滤 NSFetchedResultsController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32710633/