如何显示和隐藏标签?

时间:2019-10-02 17:26:20

标签: swift swift4

我有4个标签(dayString1,dayString2,dayString3和dayString4),其中将放置一个数值,我需要做的是,如果dayString1的内容小于dayString2的显示内容,并且总和为60 dayString1 + dayString2的值小于60,则出现dayString3,依此类推;我的逻辑是这样,但它给出了错误:

  

(对运算符'<'的不明确引用)

func chooseDays() {
        self.dayString = dayTextField.text!
        self.dayString2 = dayTextField2.text!
        self.dayString3 = dayTextField3.text!
        self.dayString4 = dayTextField4.text!

        if dayString < 60 {
            self.dateTextField2.isHidden = false
            self.dayTextField2.isHidden = false

            self.dateTextField3.isHidden = true
            self.dayTextField3.isHidden = true
            self.dateTextField4.isHidden = true
            self.dayTextField4.isHidden = true

            SearchConstraint.constant = 72

            if dayString + dayString2 < 60 {
                self.dateTextField2.isHidden = false
                self.dayTextField2.isHidden = false
                self.dateTextField3.isHidden = false
                self.dayTextField3.isHidden = false

                self.dateTextField4.isHidden = true
                self.dayTextField4.isHidden = true

                SearchConstraint.constant = 112

                if dayString + dayString2 + dayString3 < 60 {
                    self.dateTextField2.isHidden = false
                    self.dayTextField2.isHidden = false
                    self.dateTextField3.isHidden = false
                    self.dayTextField3.isHidden = false
                    self.dateTextField4.isHidden = false
                    self.dayTextField4.isHidden = false

                    SearchConstraint.constant = 152
                }
            }
        }
        return
    }

1 个答案:

答案 0 :(得分:0)

您需要先将字符串类型转换为整数,然后再与另一个整数进行如下比较:

if Int(dayString) < 60 {

也可以这样做,以免发生解包错误:

    self.dayString = dayTextField.text ?? "0"
    self.dayString2 = dayTextField2.text ?? "0"
    self.dayString3 = dayTextField3.text ?? "0"
    self.dayString4 = dayTextField4.text ?? "0"