简体   繁体   English

创建序列并通过Swift将其附加在两个视图控制器之间?

[英]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.

相关问题 两个视图控制器之间的争论 - Segue between two view controllers 展开前后两个视图控制器之间的Segue - Unwind Segue Between Two View Controllers Back and Forth Swift Swift - 如何在两个子视图控制器之间进行切换 - Swift - How to segue between two child view controllers 通过segue在视图控制器之间传递数据 - Passing data between view controllers through segue 在两个视图控制器之间生成一个 segue - Generating a segue between two view controllers 如何以编程方式创建segue以在视图控制器之间传递信息 - Swift - How can I create a segue programmatically to pass info between view controllers - Swift iOS-如何在通过手动Segue链接的两个视图控制器之间传递信息? - iOS - How can I pass information between two view Controllers linked through a Manual Segue? 在多个视图控制器之间共享数据而无须隔离(Swift 3) - Sharing data between multiple view controllers without segue (Swift 3) 在Xcode 6和Swift中通过UIButton崩溃在两个视图控制器(模态)之间进行争用 - Segue between 2 view controllers (modal) via UIButton crash in Xcode 6 and Swift 不断地在视图控制器之间传递数据而不会引起冲突? 使用SWIFT - Pass data between view controllers constantly without a segue? USING SWIFT
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM