Loading ViewController from xib file

前端 未结 10 2404
我在风中等你
我在风中等你 2020-12-08 02:33

I had a MyViewController.swift and a MyViewController.xib presenting the layout of MyViewController.

I tried different methods to load this

10条回答
  •  天命终不由人
    2020-12-08 02:53

    I removed File owner’s class name and set that to the class name of first view. And then I had to set outlets to the components which I’m going to use.

    Then I loaded that view class like

    let myViewController = Bundle.main.loadNibNamed("MyViewController", owner: self, options: nil)?.first as! MyViewController
    view.addSubview(myViewController)
    

提交回复
热议问题