0

Ok, so I'm working in Swift and I have my ViewController and my Game Scene view since it's a sprite kit game. Right now I have an NSTimer in my View Controller that counts down from 3. When it reaches 0, the timer stops. Here I have made this happen:

@IBOutlet weak var countdownTestLabel: UILabel!

    var countdown = NSTimer()
    var counter = 3

    func updateCounter() {
        countdownTestLabel.text = String(counter--)

        if counter == 0 {
            countdown.invalidate()
            //Then trigger segue to Game Scene view

        }
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        //Setting up countdown timer

        countdownTestLabel.font =  UIFont(name: "DIN Condensed", size: 30)
        countdownTestLabel.text = "\(counter)"

        countdown = NSTimer.scheduledTimerWithTimeInterval(1, target:self, selector: Selector("updateCounter"), userInfo: nil, repeats: true)

When the timer stops, I need to perform a segue that loads my Game Scene view. I know how to do this with a button (control dragging), but I need to do this programmatically.

I've tried doing something like self.presentViewController(secondViewController, animated: true, completion: nil) but I don't know how to define secondViewController as my Game Scene and I run into errors. What should I do?

blue
  • 7,175
  • 16
  • 81
  • 179
  • Are you trying to display an SKScene subclass or a UIVewController subclass? I feel when you are saying segue you mean just displaying a scene. – Skyler Lauren Jul 05 '15 at 20:52

1 Answers1

1

You have a couple of options.

You can control-drag from your source view controller to your destination view controller and create a view controller level segue. You would then give it a unique identifier and then use performSegueWithIdentifier:sender: to invoke it.

The other option would be to give your view controller's scene a unique identifier, create an instance of that view controller using instantiateViewControllerWithIdentifier: and then invoke it with `presentViewController:animated:'

Duncan C
  • 128,072
  • 22
  • 173
  • 272