You need to assign a Storyboard ID
to the view controllers you are going to use programatically:
- Select storyboard
- Go to
Identity Inspector
(⌥⌘3
)
- Assign
Storyboard ID
If you want to add manual segue in Storyboard (Note: you can have multiple manual segues):
- Select storyboard
- Select the source view controller
- Go to
Connections Inspector
(⌥⌘6
)
- In the
Triggered Segues
, drag the dot beside manual
to the target view controller and select the desired method
- In
Document Outline
, select "Show segue..." and go to Attributes Inspector
(⌥⌘4
) and assign an Identifier
In your button function, you can simply use the segue by:
self.performSegue(withIdentifier: "<IdentifierForSegue>", sender: self)
Or if you do not wish to use a manual segue:
// If view controllers are in the same Storyboard
let storyboard = self.storyboard!
// If view controllers are in different Storyboards
// let storyboard = UIStoryboard.init(name: "<NameOfYourStoryboard>", bundle: nil)
let viewController = storyboard.instantiateViewController(withIdentifier: "<IdentifierForTargetViewController>")
// If you don't have a navigation controller
self.present(viewController, animated: true, completion: nil)
// If you have a navigation controller
// self.navigationController?.pushViewController(viewController, animated: true)