Swift present ViewController programmatically while showing segues(arrows) in storyboard

I really love the graphical interface of the storyboard designer in Xcode, because all the segues are displayed with an arrow. enter image description here

But sometimes, when there is more complexity (e.g. variable to pass), I have to use a programatic way to switch to another ViewController.

let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "HomeViewController") as! HomeViewController

// pass variable
nextViewController.email = self.textfieldEmail.text!

self.present(nextViewController, animated:true, completion:nil)

I dislike, that some of the segues in my App are displayed with an arrow in storyboard, while the more complex ones are not. Is there any way to show those more complex segues with an arrow in the Main.storyboard?

Upvotes: 0

Views: 292

Answers (1)

Michał Kwiecień
Michał Kwiecień

Reputation: 2874

There are two ways to achieve this:

  1. You can create segues in interface builder and pass data in prepareForSegue method
  2. When using code to switch controllers you can still create segue in your storyboard that you will not use - just for visualisation

Upvotes: 1

Related Questions