Create a segue and attach it between two view controllers through Swift?

随声附和 提交于 2019-12-02 12:58:04

问题


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. 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:

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

回答1:


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)

or

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



来源:https://stackoverflow.com/questions/37063674/create-a-segue-and-attach-it-between-two-view-controllers-through-swift

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!