iosswiftuiviewcontrolleroutlet

Outlets in UIViewController


I have loaded a viewController's view to an other viewController's view in Swift.

let myCustomView = MyCustomView()

let myView = NSBundle.mainBundle().loadNibNamed("xibView", owner: myCustomView, options: nil)[0] as UIView

self.view.addSubview(myView)

When I have tried to add an UITableView to my MyCustomViewController (.xib), it works. But, if I add outlets like "DataSource"/"Delegate" or an action on a button : the application crashed.

Regards


Solution

  • Try different approach to load a UIView from xib

    let namedNib = UINib(nibName: "xibView", bundle: nil)
    let aNib = namedNib.instantiateWithOwner(self, options: nil)
    let myView = aNib.first as UIView
    self.view.addSubview(myView)