Xcode 模拟器出现白屏
White Screen on Xcode simulator
当我运行代码时,只显示白屏,
我遇到的问题是 线程 1:“[ setValue:forUndefinedKey:]:此 class 与键 calculateButtonLabel 的键值编码不兼容。” 在 AppDelegate.swift 文件中。
起始项目在这里:https://github.com/appbrewery/BMI-Calculator-iOS13
我的 CalculateViewController 代码(第一个):
import UIKit
class CalcualteViewController: 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()
}
var bmiValue = "0.0"
@IBAction func heightSliderChanged(_ sender: UISlider) {
let height = String(format: "%.2f", sender.value)
heightLabel.text = "\(height)m"
}
@IBAction func weightSliderChanged(_ sender: UISlider) {
let weight = String(format: "%.0f", sender.value)
weightLabel.text = "\(weight)Kg"
}
@IBAction func calculatePressed(_ sender: UIButton) {
let height = heightSlider.value
let weight = weightSlider.value
var bmi = weight / (pow(height, 2))
bmiValue = String(format: "%.1f", bmi)
performSegue(withIdentifier: "goToResult", sender: self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "goToResult"{
let destinationVC = segue.destination as! ResultViewController
destinationVC.bmiValue = bmiValue
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
}
}
我的 ResultViewController 代码(第二个):
import UIKit
class ResultViewController: UIViewController {
@IBOutlet weak var bmiLabel: UILabel!
@IBOutlet weak var adviceLabel: UILabel!
var bmiValue: String?
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func recalculateButton(_ sender: UIButton) {
self.dismiss(animated: true, completion: nil)
}
在您的代码库中的某处,可能是 xib 文件或情节提要,您有对 calculateButtonLabel
的引用,但未链接到任何内容。我最好的猜测是你曾经有一个不再存在的链接到它的 IBOutlet。
您链接的 GitHub 存储库不包含对 calculateButtonLabel
的引用,它在模拟器 (Xcode 12.1) 中构建和运行良好。
当我运行代码时,只显示白屏,
我遇到的问题是 线程 1:“[
起始项目在这里:https://github.com/appbrewery/BMI-Calculator-iOS13
我的 CalculateViewController 代码(第一个):
import UIKit
class CalcualteViewController: 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()
}
var bmiValue = "0.0"
@IBAction func heightSliderChanged(_ sender: UISlider) {
let height = String(format: "%.2f", sender.value)
heightLabel.text = "\(height)m"
}
@IBAction func weightSliderChanged(_ sender: UISlider) {
let weight = String(format: "%.0f", sender.value)
weightLabel.text = "\(weight)Kg"
}
@IBAction func calculatePressed(_ sender: UIButton) {
let height = heightSlider.value
let weight = weightSlider.value
var bmi = weight / (pow(height, 2))
bmiValue = String(format: "%.1f", bmi)
performSegue(withIdentifier: "goToResult", sender: self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "goToResult"{
let destinationVC = segue.destination as! ResultViewController
destinationVC.bmiValue = bmiValue
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
}
}
我的 ResultViewController 代码(第二个):
import UIKit
class ResultViewController: UIViewController {
@IBOutlet weak var bmiLabel: UILabel!
@IBOutlet weak var adviceLabel: UILabel!
var bmiValue: String?
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func recalculateButton(_ sender: UIButton) {
self.dismiss(animated: true, completion: nil)
}
在您的代码库中的某处,可能是 xib 文件或情节提要,您有对 calculateButtonLabel
的引用,但未链接到任何内容。我最好的猜测是你曾经有一个不再存在的链接到它的 IBOutlet。
您链接的 GitHub 存储库不包含对 calculateButtonLabel
的引用,它在模拟器 (Xcode 12.1) 中构建和运行良好。