0

I've been trying to pass data to another View Controller. But as I have two Bar Buttons that lead to two different View Controllers I have to set a condition. But when I try to pass the data it won't work. Here's the code I've been using:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if (segue.identifier == "ViewController") {

        let destViewController = segue.destinationViewController as! ViewController

        destViewController.chips = chips
        destViewController.blind = blind

    }
}

I have my destination Storyboard id to ViewController but when ViewController view opens the data isn't passed through.

EDIT:

In both View Controllers chips and blind are declared as:

var chips = 0
var blind = 0

Before I added a back button the data was passed correctly. But then the application crashed every time I clicked "Back" so I decided to add a condition which doesn't seem to work.

1 Answers1

0

I'm very new to Xcode/Swift, but I believe the string in your if (segue.identifier == "ViewController") is the problem. Instead of "ViewController" you need to use the identifier of your segue. Select your segue in Main.storyboard, click on the Attributes Inspector and give it a name in the Identifier field. That's the string you want to use.

CALL-151
  • 506
  • 3
  • 12