swift - 设置 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)"
解决方案
推荐阅读
- javascript - 通过JSON解析后的VUE.JS得到错误的输出
- sql - SQL Server 扩展表并在日期范围内为每一行添加日期
- ansible - 无法让 Ansible 在 Azure Pipelines 上运行以进行配置管理
- macos - 使用 com.apple.mail.plist 进行邮件帐户切换的终端快捷方式
- php - 如何使用带有 foreach 循环的下拉列表将数据插入数据库
- c - CreateFile - dwDesiredAccess
- django - 想要打印用户所属的所有组
- performance - golang lambda中的快速重新发送响应
- android - 如何在 DialogFragment 中更改文本颜色或日期选择器的分隔线颜色?
- node.js - Heroku 被拒绝,无法编译 nodejs。React、nodejs、express 框架