简体   繁体   中英

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''"

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?

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.

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

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

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

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>)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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