“逻辑”在视图或视图控制器中?

发布于 2024-11-07 10:16:15 字数 401 浏览 0 评论 0原文

我计划为 iphone 编写一个 LCD 数字/7 段显示器。
(由多个数字组成的显示,每个数字由 7 个(破折号)段组成。)

  1. 我的问题是,在 mvc 模式之后,“数字解析”代码属于哪里?视图或其控制器?

那么,控制器是否应该传递视图只是一个数字来显示,让 -drawRect 方法找出要照亮的部分?

或者控制器应该在控制器类中的方法中找到后直接传递视图,哪些部分要照亮?

据我所知,到目前为止,控制器负责所有逻辑事务。但我不确定这种逻辑是否也是这个意思。

  1. 哦,顺便说一句,控制器应该只在视图上设置属性,还是最好从视图类中调用控制器作为委托来获取数据?

I aam planning to write a lcd numeric / 7 segment display for iphone.
(a display that consists of several numbers, each consisting of 7 (dash) segments.)

  1. My question is, after mvc pattern, where does the 'number parsing' code belong? View or its controller?

So, should the controller pass the view just a number to display, letting the -drawRect method find out which segments to lighten up?

Or should the controller pass the view directly, which segments to lighten up, after finding that out in a method within the controller class?

As i learned so far, the controller is responsible for all logic things. But i'm not sure if that kind of logic is also meant by that.

  1. Oh and by the way, should the controller just set properties on the view, or would it be better to call the controller as a delegate from within the view class to fetch the data?

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

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

发布评论

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

评论(1

呢古 2024-11-14 10:16:16

我想说视图应该弄清楚要绘制哪些部分。理想情况下,您只需更换视图就可以将应用程序变成模拟时钟(因为从控制器传递的数字不会改变。)虽然您不希望视图执行业务逻辑,但“视觉”逻辑(如何绘制数据)绝对在视图的范围内。

I would say that the view should be figuring out which segments to draw. Ideally, you would be able to turn your app into an analog clock by just swapping out the view (since the numbers delivered from the controller wouldn't change.) While you don't want your view performing business logic, "visual" logic (how data should be drawn) is definitely within the purview of the view.

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