Is there any way instantiateViewController without using storyboard ? I did not use storyboard.
1 Answer
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()
7 Comments
Kristoff
thank you! let main = UIViewController() it worked I will accept your answer as correct
mfaani
@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...
Oleg Gordiichuk
@Honey first approach could be used with nibs also.
rmaddy
@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
@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.
|
let viewController = MyViewController(). What's the question?