[英]separate view from controller
In order to respect the MVC pattern, I would like to dissociate the view from the controller. 为了遵守MVC模式,我想将视图与控制器分离。 For example
例如
In my controller, I set the view self.view = ... 在我的控制器中,我设置视图self.view = ...
But when I push a button in the view, it should call a method from the controller BUT the view shouldn't know its controller right ? 但是,当我在视图中按下一个按钮,它应该调用来自控制器的方法,但认为不应该知道它的控制权?
So how can I link the view to the controller ? 所以,我怎么可以链接视图控制器?
以编程方式将按钮目标设置为QuestionViewController的对象。
With iOS in most cases you can get the job done with only sub classing the controller part, and not the views. 在大多数情况下,使用iOS,您可以仅对控制器部件进行子分类,而不能对视图进行分类。 So you use the UIKit provided classes straight 'out of the box'.
因此,您可以直接使用UIKit提供的类。
It's is possible because: 之所以可能是因为:
Personally, I only subclass views when I need custom drawing. 就个人而言,我仅在需要自定义绘图时才将视图分类。
So, the View INSTANCE obviously 'knows' its controller, but it is all done through generic interfaces, and so the view CODE is ignorant of your controller. 因此,View INSTANCE显然“知道”其控制器,但这都是通过通用接口完成的,因此View CODE不了解您的控制器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.