問題描述
為什麼segues不起作用?無法切換視圖 (Why segues does not work? can not switch view)
**不太清楚為什麼按下計算按鈕時視圖沒有改變?可能的原因是什麼?你能幫忙嗎?
import UIKit
class CalculateViewController: UIViewController {
@IBOutlet weak var heightLabel: UILabel!
@IBOutlet weak var weightLabel: UILabel!
@IBOutlet weak var heightSlider: UISlider!
@IBOutlet weak var weightSlider: UISlider!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func heightSlided(_ sender: UISlider) {
var currentHeightValue = sender.value
let roundedHeightValue = String(format: "%.2f", currentHeightValue)
heightLabel.text = "\(roundedHeightValue)m"
}
@IBAction func weightSlided(_ sender: UISlider) {
var currentWeightValue = sender.value
let roundedWeightValue = String(format: "%.0f", currentWeightValue)
weightLabel.text = "\(roundedWeightValue)kg"
}
@IBAction func calculateBMI(_ sender: UIButton) {
var squareOfHeight = Float(pow(heightSlider.value, 2.0))
var BMI = weightSlider.value / squareOfHeight
self.performSegue(withIdentifier: "goToResult", sender: self)
}
}
</code></pre>
參考解法
(by Natalie)
參考文件