Tuesday 15 April 2014

objective c - proper use of viewcontrollers and MVC pattern in iOS -


I have often seen that all instances are being posted on the Internet, in which a view in the root view The view is added Controller inside a lifecycle method in iOS

  - (zero) viewDidoadload [[Super Viewedload]; // slider 1 slider = [[DCSlider alloc] initWithDelegate: self]]; Slider.tag = 0; Slider.frame = CGRactam (0,0,20,100); [Slider addTarget: Self-action: @Selector (control based change) control events: UI ControlAventWalls]; [Self. Slider Container Ad Sueview: Slider]; // Slider 2 slider 2 = [[[DCSlider alloc] initWithDelegate: self]]; Slider2.tag = 1; Slider 2 Frame = CGRactam (0,0,20,100); [Slider 2adress: Action by itself: @sillector (control beet value change change) Control events: UI ControlAventWalls]; [Self. Slider Container 2 Adsview: Slider 2]; }  

But, can not it break the MVC pattern?

Because, according to my understanding, ViewControllers are considered to be only controllers and should not participate in direct visual modification activities. Is there a way to create code in different blocks of view and controllers?

good question

And no, it does not break the MVC pattern.

Controller "management" ideas, which can certainly be many; They can manipulate data to present through ideas; They can manipulate the position of ideas they manage; Or they can create ideas that are presented to themselves - including the "management" instrument. In this definition, I think it is safe to say that the controller will include visual modification without breaking the MVC pattern directly. should do.

addSubview: The method inside the controller is OK! The controller has the view "Management" under it, by adding a subview that is managed by the same controller.

Of course, if a visual hierarchy is complex and if many considerations are doing a specific task different from the controller, which you think can be modular, then you can give them your controller and They can add hair control without breaking any pattern.


No comments:

Post a Comment