Linking xib with .swift

0

I have already asked a similar question, but I am going to focus more on what I do not understand. The doubt comes from the storyboard and / or the .xib files linked to their respective classes.

When you create a controller in the storyboard, you have to link it with your class (which, from what I understand, would be your File's Owner), so you can also create your outlets and actions. Now what gives me doubt, why do I have to link the .xib file (or the storyboard viewController) with the class and it's not the other way around?

That is, if the object that is instantiated is the .swift (which contains the subclass of the UIViewController ), because the xib file is linked to the class and not in the opposite way? It is more logical to create the controller object, and at the same time, link it with the .xib file

    
asked by MatiEzelQ 12.04.2016 в 19:01
source

1 answer

2

If what I have understood is that we do not assign the view to the controller and not the controller in sight, then I would say that because logic establishes it.

When you assign a class to a storyboard controller, what you are basically saying is who is going to handle me or who will be my owner, the ViewController could not apply that rule because the view does not handle the controller but vice versa the driver is the one who handles the view.

Anyway you have other ways of eg loading .xib without specifying it in the Storyboard, I'll give you an example.

if let menuTable = NSBundle.mainBundle().loadNibNamed("MenuTableView", owner: self, options: nil).first as? MenuTableView {
            let items = ["Item 1","Item 2"]
            menuTable.items = items
            self.view.addSubview(menuTable)
        }
    
answered by 20.04.2016 / 11:03
source