gpt4 book ai didi

swift - 如何显示和隐藏标签?

转载 作者:行者123 更新时间:2023-11-30 10:35:06 24 4
gpt4 key购买 nike

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

(Ambiguous reference to operator function '<')

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com