我想采用这些文本字段并在它们之间建立一个等式。我遇到的问题是在我的方程式完成后自动更新最终的文本字段
在这种情况下,我希望在更新车辆价格或更新服务合同时更新总现金价格,而无需按下 DP 按钮。
有人可以给我一个关于如何做到这一点的建议。
代码:
@IBAction func DPButtonPressed(_ sender: Any) {
totalCashPrice.integerValue = vehiclePrice.integerValue + serviceContract.integerValue + salesTax.integerValue
}
而不是它@IBOutlet func DPButtonPressed(_sender: Any)
,我希望该功能自动完成。
这是我坚持使用委托的地方
override func viewDidLoad() {
super.viewDidLoad()
totalCashPrice.delegate = self
}
func textFieldDidBeginEditing(textField: NSTextField!) {
}
func textFieldShouldEndEditing(textField: NSTextField!) -> Bool {
return false
}
func textFieldShouldReturn(textField: NSTextField!) -> Bool {
totalCashPrice.resignFirstResponder()
return true
}
@IBAction func DPButtonPressed(_ sender: Any) {
totalCashPrice.integerValue = vehiclePrice.integerValue +
serviceContract.integerValue + salesTax.integerValue
textFieldShouldEndEditing(textField: totalCashPrice)