Search code examples
iosmodel-view-controllerios6uiviewcontroller

Does styling UI objects in iOS violate MVC?


I'm somewhat new to MVC and iOS development, and I can't seem reconcile how UI styling fits into this paradigm.

My view of MVC is built using storyboards, and I can apply primitive styling through Xcode's attribute inspector, but anything more complicated I have to use the Controller to style. For example:

- (void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated]; // required

    // set background color of view
    [[self view] setBackgroundColor:[UIColor darkGrayColor]];
}

This seems to be a clear violation of MVC, as I'm applying style logic inside of the controller's code. I find this analogous to writing an HTML app and instead of using style sheets, I write code to apply styles locally in JavaScript. Is this a weakness of iOS or am I just doing it wrong?


Solution

  • Taken from Apple's docs :

    some controller objects might also tell a view object to change an aspect of its appearance or behavior

    And it does make sense as the view is supposed to be passive and only reflect the application state as a UI and the controller will "tell" the view if some of its content needs to be changed according to user actions. (e.g background change, visibility of controls etc...)