简体   繁体   中英

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. 在此处输入图片说明

But sometimes, when there is more complexity (eg 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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM