Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Segue default value

Ive got 4 buttons in my FirstViewController. Each button has a value (1, 2, 3 and 4). Then, when i press one of the buttons, it will write something in the label on the second page. BUT... When i go back and press another button, the first value and the value from the button i choosed now, will be putted together. How do i make a default with a value of 0, everytime i go back to the buttons (FirstViewController)?

Perhaps you could post a couple of screen shots of your storyboard- I am having a little difficulty understanding exactly what you would like to accomplish. Thanks

1 Answer

import UIKit

class ViewController: UIViewController {

    var lande = 0

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func spainBut(sender: UIButton) {
        lande = lande + 1
        performSegueWithIdentifier("sideSkift", sender: sender)
    }

    @IBAction func denmarkBut(sender: UIButton) {
        lande = lande + 2
       performSegueWithIdentifier("sideSkift", sender: sender)
            }
    @IBAction func italyBut(sender: UIButton) {
        lande = lande + 3
        performSegueWithIdentifier("sideSkift", sender: sender)
    }




    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "sideSkift" {
            let sideKontrol = segue.destinationViewController as! SecondVC

            if lande == 1 {
                sideKontrol.segueText = "Madrid"
            }
            else if lande == 2 {
                sideKontrol.segueText = "København"
            }
            else if lande == 3 {
                sideKontrol.segueText = "Rom"
            }
            else {
                sideKontrol.segueText = "Du har ikke trykket"
            }

        }

    }

When i go back from SecondVC to FirstViewController (via Navigation), it will put the numbers of buttons I've chosen together? I want it to have a default value of 0 everytime i go back to FirstViewController