gpt4 book ai didi

ios - Int 在 UILabel 中没有达到 11

转载 作者:可可西里 更新时间:2023-11-01 01:48:54 25 4
gpt4 key购买 nike

我有一个 nihoshim UILabel,他的最后一个字符是 0,每次 else 语句为真并调用时,我都想更新它,一切正常,直到它达到 10,然后它突然等于 1,

 guard var yoo = Int(nihoshim.text!.suffix(1)) else {
return
}
var alephbet = ["א","ב","ג","ד","ה","ו","ז","ח","ט","י","כ","ל","מ","נ","ס","ע","פ","צ","ק","ר","ש","ת"]
nihoshim.text! = "ניחושים: " + String(yoo)
if gameLabel.text!.count <= 3 && (sender.tag == 18 || sender.tag == 20) {
gameLabel.text = gameLabel.text! + alephbet[alpha.index(after: tag) - 1]
sender.isHidden = true
} else if sender.tag == 10 && !(gameLabel.text?.contains("יי"))!{

sender.isHidden = false
gameLabel.text = gameLabel.text! + alephbet[alpha.index(after: tag) - 1]
}
else {
yoo += 1
nihoshim.text! = "ניחושים: " + String(yoo)
sender.isHidden = true
print(yoo)
}

当我打印它时,即使是 yoo 的值也无缘无故地变为 0。当我将它更新为 yoo += 20 我点击它几次,它仍然是 20,再点击一次它变为 1。

最佳答案

问题是您只检查最后一个字符,您需要在字符串末尾获取整数,例如:

let numberString = nihoshim.text!.split(separator: " ").last ?? nihoshim.text!.suffix(0)

在你的代码中它看起来像这样:

let numberString = nihoshim.text!.split(separator: " ").last ?? nihoshim.text!.suffix(0)
guard var yoo = Int(numberString) else {
return
}
var alephbet = ["א","ב","ג","ד","ה","ו","ז","ח","ט","י","כ","ל","מ","נ","ס","ע","פ","צ","ק","ר","ש","ת"]
nihoshim.text! = "ניחושים: " + String(yoo)
if gameLabel.text!.count <= 3 && (sender.tag == 18 || sender.tag == 20) {
gameLabel.text = gameLabel.text! + alephbet[alpha.index(after: tag) - 1]
sender.isHidden = true
} else if sender.tag == 10 && !(gameLabel.text?.contains("יי"))!{

sender.isHidden = false
gameLabel.text = gameLabel.text! + alephbet[alpha.index(after: tag) - 1]
}
else {
yoo += 1
nihoshim.text! = "ניחושים: " + String(yoo)
sender.isHidden = true
print(yoo)
}

关于ios - Int 在 UILabel 中没有达到 11,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56524087/

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