1

I want to perform a segue from my loading viewController to the next viewController when an animation is finished:

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)

    UIView.animateWithDuration(1.5, delay: 0.5, options: UIViewAnimationOptions.CurveLinear, animations: {
        self.loggo_image.alpha = 1.0

        self.performSegueWithIdentifier("LogInView", sender: nil)
        }, completion: nil)

}

I know the code itself probably is wrong, but it's just there displaying the example. Since I don't have any buttons or similar to create a segue to the next view in the storyboard (CTRL click in storyboard), I guess I need to do it programmatically. Though I can't work out how to set the "identifier" of the view I want to go to. As shown in the example, I tried simply using the custom class name, which isn't right.

So how? Is it Storyboard ID? Title?

Ahmad F
  • 30,560
  • 17
  • 97
  • 143
Benni
  • 969
  • 1
  • 19
  • 29
  • refer https://developer.apple.com/library/content/featuredarticles/ViewControllerPGforiPhoneOS/UsingSegues.html – Suhit Patil Oct 19 '16 at 10:05

2 Answers2

2

Let's walk through your issue:

I want to perform a segue from my loading viewController to the next viewController when an animation is finished

When an animation finished means that the code is wrong (you are right for saying "I know the code itself probably is wrong"), you should perform your the segue in the completion block, as follows:

UIView.animateWithDuration(1.5, delay: 0.5, options: UIViewAnimationOptions.CurveLinear, animations: {
            self.loggo_image.alpha = 1.0
            }, completion: { _ in
                self.performSegueWithIdentifier("LogInView", sender: nil)
        })

Though I can't work out how to set the "identifier" of the view I want to go to. As shown in the example, I tried simply using the custom class name, which isn't right.

So how? Is it Storyboard ID? Title?

I fully described how to exactly achieve this in this answer.

ALSO:

If you had a case that you should navigate to another viewController without using segues, you check this (In this case you have to use Storyboard ID):

let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)

// "nextView" is Storyboard ID
let nextViewController = storyBoard.instantiateViewControllerWithIdentifier("nextView") as NextViewController

// now you can choose between pushing:
self.navigationController?.pushViewController(nextViewContro‌​ller, animated: true)
// or presenting:
self.presentViewController(nextViewController, animated:true, completion:nil)

Hope that helped.

Community
  • 1
  • 1
Ahmad F
  • 30,560
  • 17
  • 97
  • 143
1

You can Ctr-Drag from the ViewController itself (the yellow circle on the screenshot) to the viewcontroller you want to segue to.

enter image description here

It will create a segue and you can set its identifier there and then call performSegue as you did, using the identifier you set in the storyboard.

enter image description here

smeshko
  • 1,184
  • 13
  • 27