简体   繁体   English

Swift在Storyboard中显示Segues(箭头)时以编程方式呈现ViewController

[英]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. 我真的很喜欢Xcode中情节提要设计器的图形界面,因为所有segues都用箭头显示。 在此处输入图片说明

But sometimes, when there is more complexity (eg variable to pass), I have to use a programatic way to switch to another ViewController. 但是有时候,当有更多的复杂性(例如要传递的变量)时,我不得不使用一种编程方式来切换到另一个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? 有没有办法在Main.storyboard中用箭头显示那些更复杂的标记?

There are two ways to achieve this: 有两种方法可以实现此目的:

  1. You can create segues in interface builder and pass data in prepareForSegue method 您可以在界面构建器中创建segue,并在prepareForSegue方法中传递数据
  2. When using code to switch controllers you can still create segue in your storyboard that you will not use - just for visualisation 使用代码切换控制器时,您仍然可以在情节提要中创建不使用的segue-仅用于可视化

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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