创建一个segue并通过Swift将它连接到两个视图控制器之间? [英] Create a segue and attach it between two view controllers through Swift?

查看:118
本文介绍了创建一个segue并通过Swift将它连接到两个视图控制器之间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何在不使用Storyboard的情况下以编程方式快速创建segue。由于应用程序的结构,我不能使用故事板,因此我需要知道如何以编程方式进行操作。

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.

基本上,我想要做的就是创建一个segue,并将它附加在源和目的地之间。

Essentially, all I want to do is create a segue, and attach it between the source and the destination.

到目前为止,我已经创建了一个RollSegue类,它是UIStoryboardSegue的子类。现在,我正在尝试执行以下操作:

So far, I have created a RollSegue class which is a subclass of UIStoryboardSegue. Now, I'm trying to do the following:

var seg: RollSegue = UIStoryboardSegue("roll", self, destination)

我也试过:

var seg: UIStoryboardSegue = UIStoryboardSegue("roll", self, destination)

这些代码行运行正常,但是当我尝试调用performSegue方法时,我收到错误:

These lines of code run fine, but when I try to call the performSegue method, I get the error:

Receiver (<Home1: 0x7fc84b573fd0>) has no segue with identifier 'roll'


推荐答案

实际上,您只能在故事板上设置segue标识符。因此,如果你想在两个控制器之间导航,你应该使用

Actually, you can only set segue identifier on storyboard. So if you want to navigate between two controllers, you should use

func pushViewController(_ viewController:UIViewController,animated animated:Bool)

func presentViewController(_ viewControllerToPresent:UIViewController,animated flag:Bool,完成完成:(() - > Void)?)

这篇关于创建一个segue并通过Swift将它连接到两个视图控制器之间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆