'ui label not printing the value
Good morning. Why my code doesn't change the value of UILabel? When I click the UIButton the function has to multiply the Int value of the variable meters, filled as text, by 3 and show it in the UILabel.
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var meters: UITextField!
@IBOutlet weak var button: UIButton!
@IBOutlet weak var answer: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func buttonClicked(_ sender: UIButton) {
answer.text = String(calculateNumber(meters: Int(meters.text ?? "") ?? 0));
}
func calculateNumber(meters : Int) -> Int {
let result = meters
print(result)
return result;
}
}
Solution 1:[1]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | resand91 |

