5

Is there any way instantiateViewController without using storyboard ? I did not use storyboard.

5
  • Just create an instance of the view controller like you would any other class. What's your actual issue? Commented Apr 22, 2017 at 15:40
  • any code example ? Commented Apr 22, 2017 at 15:43
  • I don't know how to do it Commented Apr 22, 2017 at 15:43
  • For using storyboard storyboard!.instantiateViewController(withIdentifier: "Second") but I did not using storyboard Commented Apr 22, 2017 at 15:44
  • 2
    let viewController = MyViewController(). What's the question? Commented Apr 22, 2017 at 15:44

1 Answer 1

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()
Sign up to request clarification or add additional context in comments.

7 Comments

thank you! let main = UIViewController() it worked I will accept your answer as correct
@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...
@Honey first approach could be used with nibs also.
@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.
@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.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.