randomorb2110
randomorb2110

Reputation: 269

Segue to Another Storyboard Swift

I am attempting to segue to another storyboard programmatically, but every time I've tried the view loads with a black screen with no content.

Here's the code I've been working with:

let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let startingView = storyboard.instantiateViewControllerWithIdentifier("HomeScreenView")
self.showViewController(startingView, sender: self)

I've created the reference on the Origin's Storyboard of the Destination Storyboard and have also tried to call:

performSegueWithIdentifier("changeover", sender: self)

Any thoughts and suggestions would be greatly appreciated.

Upvotes: 3

Views: 9955

Answers (3)

In AppDelegate append var window: UIWindow?

    let storyboard = UIStoryboard(name: "Registration", bundle: nil)
    let registrationvc = storyboard.instantiateViewController(withIdentifier: 
        "RegistrationViewController") as! RegistrationViewController
    self.window?.rootViewController?.present(registrationvc, animated: true, 
    completion: nil)

Upvotes: 1

Akbar Khan
Akbar Khan

Reputation: 2417

"MyStoryBoard" this is the storyboard name where you want to go "StoryboardId" this is the controller id which i want to show after segue.

let storyboard = UIStoryboard(name: "Service", bundle: nil)
    let myVC = storyboard.instantiateViewController(withIdentifier: "ProfileTimelineVC") as! ProfileTimelineVC
    self.present(myVC, animated: true, completion: nil)

Upvotes: 3

dcompiled
dcompiled

Reputation: 181

I've haven't had issues using Storyboard References with segues. Here are the steps I've followed to get it working:

1) In the storyboard with the source view controller, drag a storyboard reference onto the canvas.

2) Set the reference to point to the correct storyboard name and view controller in the attribute inspector

3) Ctrl+drag from the source's view controller icon (in the top bar of the scene) to the storyboard reference in order to create a segue.

4) Set the segue to "Show" and give it the identifier "Test" in the attribute inspector

5) In your source view controller's code, at the appropriate location where you want it triggered, add the line:

performSegueWithIdentifier("Test", sender: self)

That should be everything needed for the segue to be called programmatically!

Upvotes: 8

Related Questions