Search code examples
iosswift3presentviewcontroller

swift3: How to Present xib to viewcontroller


I have added xib on another xib class as subview and unable to present from xib to view controller (Story Board controller). I tried following

1.

let screen:Screen32ViewController = Screen32ViewController()
self.view.window?.rootViewController?.present(screen!, animated: true,  completion: nil)

2.

let screen = self.storyboard?.instantiateViewController(withIdentifier: "Screen32ViewController") as? Screen32ViewController
self.present(screen!, animated: true,  completion: nil)

3.

let screen:Screen32ViewController = Screen32ViewController()
self.present(screen!, animated: true,  completion: nil)

Non of this worked for me

Thanks in advance


Solution

  • try like this

    let screen = UIStoryboard(name: "storyboard name", bundle: nil).instantiateViewController(withIdentifier: "Screen32ViewController") as?   Screen32ViewController
    self.present(screen!, animated: true,  completion: nil)