我有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
}
最佳答案
您需要将字符串转换为整数,然后才能与另一个整数进行任何比较,如下所示:
if Int(dayString) < 60 {
也可以这样做,以免发生解包错误:
self.dayString = dayTextField.text ?? "0"
self.dayString2 = dayTextField2.text ?? "0"
self.dayString3 = dayTextField3.text ?? "0"
self.dayString4 = dayTextField4.text ?? "0"
关于swift - 如何显示和隐藏标签?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58206416/