从控制器向视图发送通知是否正确?
我正在构建一个应用程序,它模拟来自传感器的信息输入流。当检测到并解析信息时,我想发送通知,这将被观察到 通过不同的视图将自身更新为给定的时间间隔。 它的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该视图应该只是一个视图,不必接收通知来更新自身。我并不是说我自己没有这样做过,因为它可以让视图自行更新。我建议您设计应用程序,以便您的视图控制器接收通知并适当更新视图。使用视图来显示并与用户交互,将任何交互更新发送到视图控制器,视图控制器将任何显示更新发送到视图。
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.