Home > Software design >  Confused regarding MVC - Where do codes that add target to a UIButton go in MVC?
Confused regarding MVC - Where do codes that add target to a UIButton go in MVC?

Time:10-12

I am specifically using XIB as my UIView, and then a UIViewController for the controller in between the (M)odel and (V)iew in MVC design pattern, as recommended by Apple..

Should I just connect the first responder outlet to the button outlet in Interface Builder or should I programmatically add it to the UIViewController-based Swift class which controls that XIB view?

I guess business logic should go in the UIViewController (C)ontroller class... but what about regular application logic? I guess add a target to a button would be considered logic.. but '(V)iew' logic...

CodePudding user response:

User should use a controller, which has view attached, to manipulate data model and update the view of the controller they are using, which is attached. This makes the most sense to me.

For specificity --> MODEL contains the business, application and data structure logic.

The Controller can utilize internal functions, classes, structs as well as external 'service' or 'manager' classes to manipulate the MODEL, which the view should have connected it to it, and thus updates from. Bingo :)

CodePudding user response:

I actually prefer to make the code targets inside XIB classes and make an output interface for the XIB then let the ViewController or whatever view conform to It. This help Make the reusable XIB much easier to use

If we depend on The Parent View to add the target methods, so every parent will use the XIB should make Its own method, and the Parent does not have the usage guidelines (Interface), So It would lead to Inconsistency and debugging difficulty

  • Related