设置UILabel的文本值会报错。

10 浏览
0 Comments

设置UILabel的文本值会报错。

每次我尝试在Swift中设置UILabel.text的值时,它都会报错“Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value”。我尝试将其设置为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)

cal84.text = "卡路里:\(cal)"

fat84.text = "脂肪:\(fat)"

sod84.text = "钠:\(sod)"

car84.text = "总碳水化合物:\(car)"

sug84.text = "总糖分:\(sug)"

pro84.text = "蛋白质:\(pro)"

calc84.text = "钙:\(cac)"

nia84.text = "烟酸:\(nia)"

vb684.text = "维生素B6:\(vb6)"

b1284.text = "维生素B12:\(b12)"

pan84.text = "泛酸:\(pan)"

0