0
我是新來的Swift,我正在做一個基本的應用程序,用輸入框中的文本改變標籤的文本,我想添加RGB滑塊來改變將被改變的標籤的顏色,但是當我嘗試移動滑塊時,我收到了錯誤。Swift滑塊 - 致命錯誤:意外地發現零,同時展開一個可選值(lldb)
致命錯誤:意外發現零而展開的可選值 (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)"
}
有人可以幫我指點迷津?
你在哪一行出錯? – Jaydeep
你有連接你的網點嗎? – the4kman
@ the4kman綠色滑塊插座沒有連接,但在代碼中,因爲它是連接大聲笑我可以刪除這個問題:C – Sam