[英]Create a segue and attach it between two view controllers through Swift?
How would we create a segue in swift programatically, without using Storyboards. 我们如何在不使用情节提要的情况下以编程方式快速创建序列。 I cannot use storyboards because of how the app is structured, so I need to know how to do it programatically.
由于应用程序的结构,我无法使用情节提要,因此我需要知道如何以编程方式进行操作。
Essentially, all I want to do is create a segue, and attach it between the source and the destination. 本质上,我要做的就是创建一个序列,并将其附加在源和目标之间。
So far, I have created a RollSegue class which is a subclass of UIStoryboardSegue. 到目前为止,我已经创建了RollSegue类,它是UIStoryboardSegue的子类。 Now, I'm trying to do the following:
现在,我正在尝试执行以下操作:
var seg: RollSegue = UIStoryboardSegue("roll", self, destination)
and I have also tried: 我也尝试过:
var seg: UIStoryboardSegue = UIStoryboardSegue("roll", self, destination)
These lines of code run fine, but when I try to call the performSegue method, I get the error: 这些代码行运行良好,但是当我尝试调用performSegue方法时,出现错误:
Receiver (<Home1: 0x7fc84b573fd0>) has no segue with identifier 'roll'
Actually, you can only set segue identifier on storyboard. 实际上,您只能在情节提要中设置segue标识符。 So if you want to navigate between two controllers, you should use
因此,如果要在两个控制器之间导航,则应使用
func pushViewController(_ viewController: UIViewController, animated animated: Bool)
or 要么
func presentViewController(_ viewControllerToPresent: UIViewController, animated flag: Bool, completion completion: (() -> Void)?)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.