1
votes

I want into xib file call these lines for opening a viewcontroller : let myViewController = MyViewController(nibName: "MyViewController", bundle: nil)

self.navigationController!.pushViewController(MyViewController(nibName: "MyViewController", bundle: nil), animated: true

1
What is your question? Can you explain what is happening when you are doing this? Also, provide more code. You can load a view controller sub class from a nub by using MyViewController() as long as the nub is also called MyViewController.xib. - Fogmeister

1 Answers

0
votes

You can instantiate a view controller with a nib with the following line

let myViewController = MyViewController(nibName: "MyViewController", bundle: nil)

If your view controller (and its nib) is inside another bundle, you also need to specify the bundle:

guard let bundle = Bundle(identifier: "com.company.App") else {
    return
}
let myViewController = MyViewController(nibName: "MyViewController", bundle: bundle)

Also make sure that your nib is named correctly and your view controller is set as the file owner of the nib.