-1

我想采用这些文本字段并在它们之间建立一个等式。我遇到的问题是在我的方程式完成后自动更新最终的文本字段

在这种情况下,我希望在更新车辆价格或更新服务合同时更新总现金价格,而无需按下 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)

在此处输入图像描述

4

1 回答 1

0

Cocoa 是事件驱动的。选择一个事件,让它驱动你。

你只需要决定你想要响应什么样的信号并配置一些东西以便你得到那个信号。只需向您自己指定“何时更新车辆价格或更新服务合同”是什么意思,即什么样的用户操作算作更新字段。

于 2020-01-05T19:42:22.587 回答