gpt4 book ai didi

ios - 单击时更新标签

转载 作者:行者123 更新时间:2023-11-30 11:59:52 25 4
gpt4 key购买 nike

我有用于在应用程序中运行历史记录的代码。

如何改进它,以便在按下时立即显示数字,而不仅仅是按 =

我的程序:

 // Connected to button "="
@IBAction func equalitySignPressed(sender: UIButton) {
if stillTyping {
secondOperand = currentInput
}
dotIsPlaced = false

addHistory(text: operationSign + displayResultLabel.text!)

switch operationSign {
case "+":
operateWithTwoOperands{$0 + $1}
case "-":
operateWithTwoOperands{$0 - $1}
case "×":
operateWithTwoOperands{$0 * $1}
case "÷":
operateWithTwoOperands{$0 / $1}
default: break
}
}
func addHistory(text: String){
//Add text
resultLabelText.text = resultLabelText.text! + "" + text
}

当前输出:

enter image description here gif

最佳答案

您可以在此处使用键值观察(KVO)。

addObserver(self, forKeyPath: #keyPath(INPUTS), options: [.old, .new], context: nil)

您可以将值观察为

override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if keyPath == #keyPath(INPUT) {
// Update UI
resultLabelText = "NEW_VALUE"
}
}

关于ios - 单击时更新标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47377618/

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