简体   繁体   English

调用情节提要场景而不快速创建情节?

[英]Call storyboard scene without creating a segue in swift?

I created a scene and tried to link the class to the scene and create a segue with the storyboard and use self.performSegueWithIdentifier("SegueID", sender: self) and no matter what I did (ie clean build) I still got the same error "reason: 'Receiver () has no segue with identifier 'SegueID''" 我创建了一个场景,并尝试将类链接到该场景,并使用情节self.performSegueWithIdentifier("SegueID", sender: self)创建了一个segue,并使用self.performSegueWithIdentifier("SegueID", sender: self) ,无论我做了什么(即,干净的构建),我仍然得到相同的结果错误“原因:'Receiver()没有标识为'SegueID的segue'”

I think the best way to solve this is to avoid the segue in this instance all together. 我认为解决此问题的最佳方法是避免这种情况下的串扰。

So is there a way to make a call from a view in the code to transition to another view without using segue in swift? 那么有没有一种方法可以在不快速使用segue的情况下从代码中的视图进行调用以过渡到另一个视图?

Edit I've tried all three ways but to no avail. 编辑我已经尝试了所有三种方式,但是都没有用。 The most common way of just creating a segue between two scenes in storyboard and giving it a name, in my case "Details", but the segue isn't recognized. 仅在情节提要中的两个场景之间创建序列并为其指定名称的最常见方法,在我的情况下为“详细信息”,但是无法识别序列。

So I tried the next way of loading it from a nib and then pushing that nib onto the navigation stack, but when compile and build the program and I click on the button to present to new view controller, nothing happens except for the function println executing. 因此,我尝试了从笔尖加载然后将笔尖推入导航堆栈的另一种方法,但是当编译并生成程序时,我单击按钮以呈现给新的视图控制器,除了执行println函数外,什么都没有发生。

And trying to use the destination controller manually just didn't work. 尝试手动使用目标控制器是行不通的。 instantiateViewControllerWithIdentifier expects a string and complains that there are too many arguments in the call InstantiateViewControllerWithIdentifier需要一个字符串,并抱怨调用中参数太多

Your code doesn't work because you need to setup a segue in storyboards with a specific ID that you pass as an argument when you call performSegueWithIdentifier . 您的代码无法正常工作,因为您需要在情节提要中设置序列号,并在调用performSegueWithIdentifier时将其作为参数传递给特定的ID。 So, in your case, you need to create a segue with ID "SegueID" , since that is the string that you are passing to that call. 因此,根据您的情况,您需要创建一个ID为"SegueID"的segue,因为这是您要传递给该调用的字符串。

If you don't want to do this using storyboards, you can still just use UINavigationController directly (after all, a segue uses a UINavigationController under the hood). 如果您不想使用情节提要板执行此操作,则仍然可以直接使用UINavigationController (毕竟,segue在后台使用UINavigationController )。

Then you just need to instantiate your destination view controller manually (eg by using 然后,您只需要手动实例化目标视图控制器(例如,通过使用

self.storyboard.instantiateViewControllerWithIdentifier(<your vc id from the storyboard>, animated:true) 

or by loading it from a nib 或从笔尖加载

init(nibName:bundle:)

and then push it onto the navigation stack using 然后使用将其推入导航堆栈

self.navigationController.pushViewController(<the formerly instantiaded vc>)

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

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