动态更改获取结果控制器的排序描述符

发布于 2024-09-06 14:36:43 字数 493 浏览 2 评论 0原文

有没有办法在 iOS 上为获取的结果控制器动态设置排序描述符?

例如,我需要根据导航标题栏中分段控件的设置对返回给我的核心数据结果进行排序。用户可以单击分段控件以按价格或优先级排序。

然后,我需要获取的结果控制器返回并显示根据分段控制值分类为多个部分的核心数据信息。

我知道如何最初设置排序描述符,但我不确定如何动态更改/更新它。由于 - (NSFetchedResultsController *)fetchedResultsController 函数是延迟加载的,它是否总是只返回第一次创建的 frc(从而返回初始排序描述符设置)?

我是否会做一些事情,例如将分段控制值存储在sharedPreferences中,然后当它发生更改时,将我的fetchedResultsController设置为nil,以便生成一个新的?然后在 fetchedResultsController 函数中,我可以根据该 sharePreferences 设置创建 sortDescriptor 吗?

Is there a way to have the sort descriptor(s) be dynamically set for a fetched results controller on iOS?

For instance, I need to have the core data results returned to me sorted based on the setting of a segmented control in the navigation title bar. The user can either click the segmented control to sort by Price or Priority.

I then need the fetched results controller to return and display the core data info sorted into sections based on that segmented control value.

I know how to set the sort descriptors initially, but I'm uncertain how to change it/update it dynamically. Since the - (NSFetchedResultsController *)fetchedResultsController function is lazy loaded, wont it always just return the frc that was created the first time through (thus returning the initial sort descriptor setting)?

Would I do something like store the segmented control value in a the sharedPreferences, and then when it is changed, set my fetchedResultsController to nil so that a new one will be generated? Then within the fetchedResultsController function I can create my sortDescriptor based on that sharedPreferences setting?

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

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

发布评论

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

评论(1

旧时浪漫 2024-09-13 14:36:43

您可以掌控一切。例如,您可以在更新分段控件时释放控制器并在表上调用重新加载。这将导致控制器使用新的排序进行重建。

还有其他解决方案,但它们取决于您的应用程序设计。

You are in control of that. You could, for example, release the controller when the segmented control is updated and call reload on your table. This would cause the controller to be rebuilt with the new sort.

There are other solutions but they depend on your app design.

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