Proper use of viewcontrollers and MVC pattern in iOS

I often saw code examples that were posted all over the Internet where some view was added to the root view in ios inside the view controller inside the lifecycle method in iOS.

- (void)viewDidLoad 
{
 [super viewDidLoad];

 // Slider 1

 slider = [[[DCSlider alloc] initWithDelegate:self]];
 slider.tag = 0;
 slider.frame = CGRectMake(0,0,20,100);
 [slider addTarget:self action:@selector(controlBassValueDidChange:) forControlEvents:UIControlEventValueChanged];
 [self.sliderContainer addSubview: slider];

 // Slider 2 

 slider2 = [[[DCSlider alloc] initWithDelegate:self]];
 slider2.tag = 1;
 slider2.frame = CGRectMake(0,0,20,100); 
 [slider2 addTarget:self action:@selector(controlBeatValueDidChange:) forControlEvents:UIControlEventValueChanged];
 [self.sliderContainer2 addSubview: slider2]; 
}

But doesn't that break the MVC pattern?

Since, in my understanding, ViewControllers should only be controllers and should not be directly involved in the activities associated with the change. Is there a way to structure the code in separate Views and Controllers blocks?

+4
source share
1 answer
Good question.

And no, it does not violate the MVC pattern.

"" , , , ; , ; , ; , , - , "". , , , MVC.

addSubview: ! "" , , , , .

, , , , , , .

+5

All Articles