Load UIViewController from the separate nib file in swift?

后端 未结 3 788
悲哀的现实
悲哀的现实 2021-02-02 10:39

I had take one ViewController with separate nib file. and my initial root viewcontroller is set in the storyBoard. Now the problem is that when I push to this controller the Vi

3条回答
  •  迷失自我
    2021-02-02 11:08

    Here is a nice generic approach...

    extension UIViewController {
        class func loadFromNib() -> T {
             return T(nibName: String(describing: self), bundle: nil)
        }
    }
    
    let vc : OfferDetailViewController = OfferDetailViewController.loadFromNib()
    

提交回复
热议问题