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
Jonas Kristensen
2,738 PointsMaking a default value when i go back
How can i make a default value everytime i go back to my FirstViewController? Ive got two viewcontrollers. The FirstViewController has four buttons, with four different values, so the Labeltext on my SecondViewController will be different for each button. But when i go back from the SecondView to the FirstView and press a new button, it will put the values together, and makes a wrong answer. I will show you the codes below, and i really hope you guys can help!
Jonas Kristensen
2,738 Pointsimport Foundation
import UIKit
class SecondVC: UIViewController {
@IBOutlet var buttonLabel: UILabel!
var segueText: String = ""
override func viewDidLoad() {
super.viewDidLoad()
buttonLabel.text = segueText
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
2 Answers
Caleb Kleveter
Treehouse Moderator 37,862 PointsYou will have to clear the array to do what you want I think, as in re-assigning the array after you go back to the first view-controller.
Jonas Kristensen
2,738 PointsCan you make me an example?
Jonas Kristensen
2,738 PointsHow do i re-assign the array after i go back to FirstView?
Caleb Kleveter
Treehouse Moderator 37,862 PointsIt might be something like this for the button:
@IBAction func homeBut(sender: UIButton) {
lande = 0
performSegueWithIdentifier("sideSkift", sender: sender)
}
I'm not sure you would need an if statement.
Jonas Kristensen
2,738 PointsI see the idea. But i can't add my "Go back" button from my SecondView to Firstview when im using the navigation?
Jonas Kristensen
2,738 PointsJonas Kristensen
2,738 Points