在没有 nib 文件的 Objective-C 中,MVC 是否将逻辑与视图放在同一个类中?
当我在 Objective-C 中以编程方式工作时,没有 nib 文件,并且逻辑在我的:
appViewController.m
在同一个类中该视图以及视图元素发生了什么?这违背了MVC模式吗?
我是否必须创建另一个班级并向两个班级发送消息?
When I work in Objective-C programatically with out nib files, and have the logic in my:
appViewController.m
having in the same class What is going on with that view, as well as with the View elements? Is this against the MVC pattern?
Do I have to create another class and message both classes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由你决定!如果您想分离层(M,V,C),您可以以编程方式创建自己的视图,并使用复合设计模式,在您的 UIView 子类中构建它,方法是从控制器中删除绘图代码。
也就是说...
,您将使用 loadView:代码显示您的视图:
It's up to you! If you want to separate layers (M,V,C) you can create your own view programmatically and, by using composite design pattern, build it in your UIView subclass, by removing drawing code from your controller.
That is...
code:
从技术上讲,它违背了MVC模式。你的 V 和 C 组合成一个对象。您可以将处理布局和绘图的代码分离到单独的 UIView 子类中。然后用loadView加载它:
为了在视图和视图控制器之间进行通信,您可以定义委托协议。
当在视图中按下按钮(或类似的其他内容)时,会将其传递给委托。 ViewController 应符合委托方法并以这种方式处理实际逻辑本身。
Technically, it is going against the MVC pattern. Your V and C and combined into a single object. You can seperate the code that handles layout and drawing into a seperate UIView subclass. Then load it with loadView:
To communicate between the view and the view controller, you can define a delegate protocol.
When a button is pressed in the view (or something else along those lines) pass that on to the delegate. The ViewController should conform to the delegate method and handle the actual logic itself that way.