gpt4 book ai didi

swift - UIAlert 问题

转载 作者:行者123 更新时间:2023-11-28 13:16:50 27 4
gpt4 key购买 nike

如果用户点击按钮并且标签文本为 0,我会尝试显示 UIAlert。我希望按钮在单击按钮后将标签文本更改为 0。当我尝试这样做时,UIAlert 在我不想要的时候出现了。这是我的按钮代码:

@IBAction func checkButton(sender: UIButton) {

if (currentCountLabel == "0"){

let alert = UIAlertView()
alert.title = "Alert"
alert.message = "You must type in an answer in order to check it"
alert.addButtonWithTitle("Understood")
alert.show()

}

currentCount *= 0
currentCountLabel.text = "\(currentCount)"

}

如何获得将标签文本更改为 0 的按钮,但在文本更改时不会出现错误?

提前致谢。

最佳答案

您正在将您的 currentCountLabel UILabel 与字符串零进行比较。您应该将 currentCountLabel 的文本与字符串零进行比较。

你可以改变你的

if (currentCountLabel == "0")

if (currentCountLabel.text == "0")

关于swift - UIAlert 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28683455/

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