当我调用函数时,我正在尝试让文本字段更新其标签。当我调用它时,我返回了可选",并且文本字段变为空白。 下面是我的代码。
func P18Switch() {
if metricImperialSwitch?.selectedSegmentIndex == 0
{
measurementSwitch = 0
CWLabel.text = "kg"; TWLabel.text = "kg"; CWaLabel.text = "cm"; TWaLabel.text = "cm"; CHLabel.text = "cm"; THLabel.text = "cm"
if CWeight.text == "" {
print("No go")
} else {
// b = 0.453592
// c = Double
// d = Double(CWeight.text!)
c = d! * b
CWeight.text = c as? String
print(CWeight.text)
}
}
我之前声明了 b、c 和 d
与其将Double
转换为String
,只需执行以下操作:
CWeight.text = String(c)