MVC设计,试图解耦我的代码

发布于 2024-12-13 09:39:05 字数 385 浏览 2 评论 0原文

所以我仍在学习,这就是我所做的。我有一个与 sqlite DB 对话的模型类。我有一个显示弹出窗口的 ViewController (FilterViewController)。在弹出窗口中,有一些不同的选项,例如分段控件、推送 tableView 的按钮等。所有这些选项都是用于过滤器来过滤向用户显示的内容。

在本课程中,我根据用户选择更新模型。然后,当更新完成后,我向处理所有其他视图(选项卡栏、搜索栏、导航栏等)的 MainViewController 类发布通知。然后在该类中,它知道数据已更改,并使用过滤后的数据更改用户的视图。

这是一个好的设计吗?我想知道 MVC 如何将视图、控制器和模型分开。但似乎在我的 FilterViewCtlr 中,我从用户(视图)获取输入,并更新模型。这是它应该如何运作的吗?谢谢!

So I'm still learning and this is what I've done. I have a model class that talks to a sqlite DB. I have a ViewController that shows a popover (FilterViewController). In the popover, there are some different options, like segment controls, a button to push a tableView, etc. All of these options are for a filter to filter out what is shown to the user.

In this class, based on user selection, I update the model. Then when the updates are done, I post a notification to the MainViewController class that handles all the other view (tabbars, search bars, navigation bars, etc). Then in that class, it knows the data was changed and alters the view for the user with the filtered out data.

Is this an ok design? I wonder how MVC works to keep the View, Controller, and Model separate. But it seems like in my FilterViewCtlr, I get input from the user (view), and update the model. Is this how it should work? Thanks!

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

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

发布评论

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

评论(1

み青杉依旧 2024-12-20 09:39:05

这就是它应该如何运作的。控制器的工作是协调视图/模型交互。

That's how it should work. The job of a controller is to mediate the view/model interactions.

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