从控制器向视图发送通知是否正确?

发布于 2024-10-31 03:26:45 字数 165 浏览 3 评论 0原文

我正在构建一个应用程序,它模拟来自传感器的信息输入流。当检测到并解析信息时,我想发送通知,这将被观察到 通过不同的视图将自身更新为给定的时间间隔。 它的 MVC 是否兼容使用通知来获取从模型/控制器到视图的连接? 我这么问是因为我经常阅读有关当用户与 UI 交互时视图向控制器发送通知的内容。

谢谢

I´m building an app which simulates an Inputstream of information from a sensor. When information are detected and parsed I want to send Notifications, that will be observed
by the different views which update themselves to a given timeintervall.
Is its MVC compliant to use Notifications to get a connection from Model/Controller to the View?
I´m asking because I´m often reading about Views sending Notifications to the Controller when a User interacted with the UI.

Thanks

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

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

发布评论

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

评论(1

旧情别恋 2024-11-07 03:26:45

该视图应该只是一个视图,不必接收通知来更新自身。我并不是说我自己没有这样做过,因为它可以让视图自行更新。我建议您设计应用程序,以便您的视图控制器接收通知并适当更新视图。使用视图来显示并与用户交互,将任何交互更新发送到视图控制器,视图控制器将任何显示更新发送到视图。

The view is supposed to be just a view and should not have to receive notifications to update itself. I am not saying I have not done this myself as it work having the view update itself. I would recommend that you design your application so that your view controllers receive the notifications and update the views appropriately. Use your views to display and interact with the user sending any interaction updates to your view controller and the view controller sending any display updates to the view.

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