首页 > 解决方案 > 设置 UILabel 的文本值会吐出错误

问题描述

每次我尝试快速设置 UILabel.text 的值时,它都会吐出错误“致命错误:在隐式展开可选值时意外发现 nil”。我正在尝试将其设置为 Double 数组中的一个值加上一个字符串。

这是代码

我尝试手动设置变量的值,我也尝试设置普通变量的值,但没有任何修复。

let normal = [10, 0, 0.105, 0.002, 0, 0, 0, 0.020, 0.00375, 0.00000192, 0.0025]
let cal = normal[0] * 1
    let fat = normal[1] * 1
    let sod = normal[2] * 1000
    let car = normal[3] * 1000
    let sug = normal[4] * 1
    let pro = normal[5] * 1
    let cac = normal[6] * 1000
    let nia = normal[7] * 100
    let vb6 = normal[8] * 1000
    let b12 = normal[9] * 1000000
    let pan = normal[10] * 1000
let caf = Double(80)
//print(caf)
cal84.text = "Calories: \(cal)"
fat84.text = "Fat: \(fat)"
sod84.text = "Sodium: \(sod)"
car84.text = "Total Carbohydrates: \(car)"
sug84.text = "Total Sugar: \(sug)"
pro84.text = "Protein: \(pro)"
calc84.text = "Calcium: \(cac)"
nia84.text = "Niacin: \(nia)"
vb684.text = "Vitamin B6: \(vb6)"
b1284.text = "Vitamin B12: \(b12)"
pan84.text = "Pantothenic Acid \(pan)"

标签: swiftxcodeuikit

解决方案


推荐阅读