Calling segue programmatically doesn't work
I am trying to make a splash screen. I have a view that has a background image drawn and then another view that I want to go to in a few seconds. I am trying to use the following code:
self.performSegueWithIdentifier("showApp", sender: self)
I created a transition between the two views by pressing Ctrl + while dragging the line from one to the other. I have set the segue id to "showApp".
When I run the code nothing happens and there are no errors. Any ideas?
Here's the controller for the splash screen:
class SplashViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
sleep(2)
// THIS DOES NOTHING:
self.performSegueWithIdentifier("showApp", sender: self)
// THIS AS SUGGESTED ALSO DOES NOTHING:
var otherViewController:UIViewController = self.storyboard.instantiateViewControllerWithIdentifier("test") as UIViewController
self.presentViewController(otherViewController, animated: true, completion: nil)
}
}
+1
source to share
1 answer
Usually you need a navigation controller to use the segue.
Select SplashViewController object inside storyboard and go to
Editor -> Inline -> Navigation Controller
After that delete the code suggested by Clement and try to run the project again, you should get the expected result.
+2
source to share