I am creating a very simple iOS application that involves two labels ("labelDisplay" and "labelStatus"), one button ("buttonAddOne") and a variable ("numbers"). I can't understand why the labelStatus isn't being updated when "numbers" reaches 5. I also tried other ways but had no luck. Here is the Swift code. Thank you! If you want to download the project: https://www.dropbox.com/s/kpv8qqquppe00jc/ProjectStackOverFlow.zip?dl=0
import UIKit
var numbers:Int = 0
class ViewController: UIViewController {
// Declaration of the two labels
@IBOutlet weak var labelDisplay: UILabel!
@IBOutlet weak var labelStatus: UILabel!
// Code for the "Add 1" button
@IBAction func buttonAddOne(sender: AnyObject) {
numbers = numbers + 1
labelDisplay.text = "\(numbers)"
}
override func viewDidLoad() {
super.viewDidLoad()
if numbers == 5 {
labelStatus.text = "Numbers variable is equal to 5! Hurray!"
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
Aucun commentaire:
Enregistrer un commentaire