Is there any way instantiateViewController without using storyboard ? I did not use storyboard.
Asked
Active
Viewed 7,008 times
5
-
Just create an instance of the view controller like you would any other class. What's your actual issue? – rmaddy Apr 22 '17 at 15:40
-
any code example ? – Kristoff Apr 22 '17 at 15:43
-
I don't know how to do it – Kristoff Apr 22 '17 at 15:43
-
For using storyboard storyboard!.instantiateViewController(withIdentifier: "Second") but I did not using storyboard – Kristoff Apr 22 '17 at 15:44
-
2`let viewController = MyViewController()`. What's the question? – rmaddy Apr 22 '17 at 15:44
1 Answers
9
Yes you can init you're controller with nib name:
let main = UIViewController(nibName: "Second", bundle: nil)
Also you can call constructor without parameters like:
let main = UIViewController()

Oleg Gordiichuk
- 15,240
- 7
- 60
- 100
-
thank you! let main = UIViewController() it worked I will accept your answer as correct – Kristoff Apr 22 '17 at 15:49
-
@Kristoff the first line is using from storyboard...basically wherever you see nibName it means *from* storyboard...The 2nd line is purely instantiating a viewController programatically...though you would also have feed the related properties of it ie buttons, labels,views,etc... – mfaani Apr 22 '17 at 15:58
-
-
1@Honey No, the first one is not using a storyboard. It's using a nib. You can have standalone nibs without ever using a storyboard. Nibs have been around much longer than storyboards. – rmaddy Apr 22 '17 at 16:31
-
@rmaddy ohh ok. Thanks for the correction. But don't you have to create that nib from storyboard? Or your saying you can create nibs programmatically? – mfaani Apr 22 '17 at 16:38
-
1@Honey No, nibs are created in Interface Builder, without using a storyboard. Or when you create a new view controller class, Xcode gives you the option of also creating a nib. – rmaddy Apr 22 '17 at 16:42
-
@rmaddy Thanks...after 3000reps you expect to learn more complex stuff rather not knowing the diff between interface builder and storyboard #facepalm! – mfaani Apr 22 '17 at 16:46