Swift Sliders - fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

Swift Sliders - fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

我是 Swift 的新手,我正在制作一个基本应用程序,它使用输入框中的文本更改标签的文本,我想添加 RGB 滑块来更改标签的颜色将被更改,但我在尝试移动滑块时立即收到错误消息。

致命错误:在展开可选值时意外发现 nil (lldb)

@IBOutlet weak var OutputLabel: UILabel!
@IBOutlet weak var InputField: UITextField!

@IBOutlet weak var RedSlider: UISlider!
@IBOutlet weak var BlueSlider: UISlider!
@IBOutlet weak var GreenSlider: UISlider!

@IBOutlet weak var RedLabel: UILabel!
@IBOutlet weak var GreenLabel: UILabel!
@IBOutlet weak var BlueLabel: UILabel!


var RedColor : Float = 0
var GreenColor : Float = 0
var BlueColor : Float = 0

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}

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


@IBAction func ChangeBtn(_ sender: Any) {
    OutputLabel.text = InputField.text
}

@IBAction func RedSliderAction(_ sender: UISlider) {
    changeColor()
}

@IBAction func GreenSliderAction(_ sender: UISlider) {
    changeColor()
}

@IBAction func BlueSliderAction(_ sender: UISlider) {
    changeColor()
}


func changeOutputLableColor() {
    OutputLabel.textColor = UIColor(red: CGFloat(RedColor), green: CGFloat(GreenColor), blue: CGFloat(BlueColor), alpha: 1.0)
    changeLabelNumbers()
}

func changeColor() {
    RedColor = RedSlider.value
    GreenColor = GreenSlider.value
    BlueColor = BlueSlider.value
    changeOutputLableColor()
}

func changeLabelNumbers() {
    let RoundedRed = String(format: "%0.0f", (RedColor * 255))
    let RoundedGreen = String(format: "%0.0f", (GreenColor * 255))
    let RoundedBlue = String(format: "%0.0f", (BlueColor * 255))

    RedLabel.text = "\(RoundedRed)"
    GreenLabel.text = "\(RoundedGreen)"
    BlueLabel.text = "\(RoundedBlue)"
}

谁能帮我解决一下?

您可能没有将 @IBOutlets RedSlider,BlueSlider and/or GreenSlider 连接到故事板上的 UISlider。这将导致您收到错误消息。

或者您可能没有连接@IBOutlets RedLabel、GreenLabel and/or BlueLabel。只需查找您的代码崩溃的那一行,它会提示您哪一行未连接。