gpt4 book ai didi

ios - Xcode 控制台错误消息 : 'fatal error: unexpectedly found nil while unwrapping an Optional value' (Swift)

转载 作者:行者123 更新时间:2023-11-30 13:12:56 24 4
gpt4 key购买 nike

我正在开发 BMICalculator。我似乎在这里找不到任何可选值。我选择了数字键盘作为键盘,这样只能输入数字。

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if let results = segue.destinationViewController as? ResultsController {

if let height = Double(heightTextField.text!), weight = Double(weightTextField.text!) {
let info = BMIInformation(cm: height, kg: weight)
let bmi = String(info.computeBMI())
results.bmiValue.text = bmi
}
}

}

这是我的结果 Controller 类:

class ResultsController: UIViewController {

@IBOutlet weak var bmiValue: UILabel!
@IBOutlet weak var bmiDescription: UILabel!

override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.
}

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

}

最佳答案

heightTextField.text!当您尝试强制解开它时可能没有值

关于ios - Xcode 控制台错误消息 : 'fatal error: unexpectedly found nil while unwrapping an Optional value' (Swift),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38537042/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com