dimanche 2 août 2015

error performing segue in Swift iOS

I've recently been playing around with swift segues and I'd love to incorporate one in my latest app, the problem is I can't seem to get them to work. So far I've created another view controller SecondViewController and referenced in my ViewController & SecondViewController files as so:

ViewController.swift

import UIKit

class ViewController: UIViewController {

var secondViewController: SecondViewController!
var viewController: ViewController!

override func viewDidLoad() {
//lots more code here

SecondViewController.swift

import UIKit

class SecondViewController: UIViewController {

var secondViewController: SecondViewController!
var viewController: ViewController!

override func viewDidLoad() {

Them in storyboard view I've crtl+dragged a segue from viewController to secondViewController and once that's been created given that segue an identifier using the right hand panel, the segue identifier is GameOver and the segue type is show.

Now I want to call the segue automatically with no interaction from the user, in the final app once the user hits the game over func it would trigger the segue and display a new UIView where the highscore could be displayed with a few other items.

The code I'm using to call the segue is:

self.viewController.performSegueWithIdentifier("GameOver", sender: self)

I receive the following error...

Thread 1:EXC_BAD_INSTRUCTION (code=EXC_1386_INVOP, subcode=0x0

I also have this error in the output field...

fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

I've played around with the names of the segues and the file names and I still get the same error, I'm sure I'm missing something fundamental so hopefully someone can help me work this out.

I've created a new project and uploaded it to GitHub, if anyone could tell me what I'm missing that would be great, here is a link to my GitHub repository http://ift.tt/1KJQlaf

Thank you.

Aucun commentaire:

Enregistrer un commentaire