I want to open new UIViewController on the button through code. I have already made the controller in storyboard and just want to link it and also I don't want to use XIB interface or nibName?
Asked
Active
Viewed 3.3k times
14
-
The answer is right here: http://stackoverflow.com/questions/25474115/how-to-load-uiviewcontroller-programmatically-from-storyboard – Scott Zhu Dec 12 '14 at 10:37
-
how to implement this if your viewcontroller has no storyboard – Kartiikeya Apr 09 '19 at 10:09
3 Answers
20
To open New view controller you need to write this line in button click event:
self.performSegueWithIdentifier("GoToViewController", sender:self)
To link up with new view controller follow this steps:
Select New view controller from storyboard & right click on it
You will find Dark dray popup will appear (see image )
Now under Presenting Segues select Present Modally & drag to the View controller from where you need to open up this view controller & link it
You will find new segue created under New view controller
Now select that segue go to inspector & copy the identifier or rename & copy it
Use that identifier in above line
Hope it will work.
-
-
If i open new view controller in your way , will the previous view controller be destructed from memory ? @cyberlobe – roy May 14 '17 at 05:43
-
1
14
self.navigationController!.pushViewController(self.storyboard!.instantiateViewControllerWithIdentifier("userProfileController") as UIViewController, animated: true)
I wanted to add my view controller to the navigation controller and this also worked

Manu Gupta
- 1,759
- 1
- 14
- 22
1
For swift 4.2, try the following code:
self.navigationController!.pushViewController(self.storyboard!.instantiateViewController(withIdentifier: "inventoryViewController") as UIViewController, animated: true)

Siong Thye Goh
- 3,518
- 10
- 23
- 31

Odwori
- 1,460
- 13
- 14