我什么时候应该将deleteCacheWithName与fetchedResultsController一起使用?

发布于 2025-01-03 19:06:46 字数 367 浏览 3 评论 0原文

当将核心数据 + 表视图与 SearchDisplayController 结合使用时,fetchedResultsController 的谓词会发生更改,以便仅获取与搜索显示中的字符串相符的结果子集。

当用户键入搜索字符串时,函数 shouldReloadDisplayForSearchString 会被多次调用。一种常见的策略似乎是简单地用新的谓词覆盖所获取的 ResultsController 的当前谓词。 Apple 建议在搜索谓词更改时调用deleteCacheWithName。

对我来说,每次都删除缓存似乎有点残酷。这是这种情况下的最佳实践吗?是否还有其他策略,例如实例化用于搜索的临时 fetchedResultsController?

感谢您的帮助!

When using core data + table views in combination with SearchDisplayController the predicate for the fetchedResultsController is changed such that only the subset of results confirming to the string in the search display are fetched.

The function shouldReloadDisplayForSearchString is called several times when the user types a search string. A common strategy seems to be to simply overwrite the current predicate for the fetched ResultsController with a new one. Apple suggests to invoke deleteCacheWithName when the search predicate is changed.

For me it seems to be a bit brutal to delete the cache every time. Is this the best practice for this case? Are there other strategies, such as instantiating a temporal fetchedResultsController for the search?

Thanks for Help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

熟人话多 2025-01-10 19:06:46

我认为,正如您所说,这有点残酷,您最好对搜索控制器使用不同的请求。例如,我不使用获取的结果控制器作为搜索控制器,而是使用对数组的请求。虽然我获取的结果控制器没有被修改。

I think that, as you said, it is a bit brutal and you'd better using a different request for search controller. I, for example, don't use a fetched results controller for search controller but a request to an array. While my fetched results controller is not modified.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文