TextField没有更新给我可选“”

时间:2017-02-09 21:59:21

标签: swift null numbers

我试图在调用函数时让textfield更新其标签。 当我调用它时,我得到一个Optional“”的返回,文本字段变为空白。以下是我的代码..

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

1 个答案:

答案 0 :(得分:0)

不要将Double转换为String,而是执行此操作:

CWeight.text = String(c)