1

I have 2 storyboards, I have common screen for both storyboards. I have created it as a separate view controller with xib. I want to load it in between storyboard screens.

ntshetty
  • 1,293
  • 9
  • 20
Arahim
  • 303
  • 1
  • 6
  • 14

2 Answers2

2

You can load VC from Nib file very easily. try the code below :

func presentMyViewController() {
    let myVC = MainViewController(nibName:"MyViewController", bundle:nil)
    self.navigationController.pushViewController(myVC, true);
    // you could present it another way, such as:
    // self.presentViewController(myVC, true, nil)
}

Edit : As per comment I don't think that we can directly load xib from story-board but if we need to navigate to xib then you can try above code or else you can also add child view controller directly on viewcontroller.

Umang Loriya
  • 840
  • 8
  • 15
0

Something like below:

You can override the loadview() method in class.

public class MyViewController {
    override func loadView() {
        Bundle.main.loadNibNamed("MyViewController", owner: self, options: [:])
    }

   //your stuff here...

}

Assumes of course your XIB is MyViewController.xib. Adjust to suit.

edit: also assumes you've correctly set up the files owner references in the XIB (i.e. to the view controller in question).

Mitchell Currie
  • 2,769
  • 3
  • 20
  • 26