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.
Asked
Active
Viewed 545 times
2 Answers
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
-
The question is how to do it in a storyboard, not the code. – Srđan Stanić Nov 10 '17 at 15:42
-
Here the question is not clear first of all and second is before downvoting any reply you should consider to give acknowledgment by posting the comment. @SrđanStanić – Umang Loriya Nov 11 '17 at 04:43
-
I'm sorry, I was too quick to downvote. Can you please edit your answer so I can upvote it? – Srđan Stanić Nov 12 '17 at 11:29
-
Edited. asking question with proper description will be helpful. – Umang Loriya Nov 13 '17 at 10:58
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