我想在我的應用程序中有一個場景,允許用戶在兩個單獨的文本字段中輸入數字,它會執行一些基本的數學運算,並在點擊時將輸出吐出到標籤中「計算按鈕」。我觀看過視頻,更改了代碼,我似乎無法按照自己的意願工作,而且我的應用一直在崩潰。這是我迄今爲止的簡單代碼。任何人都可以解釋我輸入什麼是錯誤的,我需要改變什麼?非常感謝,謝謝!簡單文本字段來更改標籤答案
import UIKit
class DopamineCalculator: UIViewController {
//Patient weight Input
@IBOutlet weak var patientWeight: UITextField!
//calculate button
@IBAction func calculateButton(sender: AnyObject) {
let weightPatient = Double(self.patientWeight.text!)
dripAnswer.text = String(weightPatient * 2)
}
//Clear button action
@IBAction func clearButton(sender: AnyObject) {
self.patientWeight.text=nil
//self.dosageDesired.text=nil
self.dripAnswer.text=nil
}
//Drip Rate Answer Label
@IBOutlet weak var dripAnswer: UILabel!
我的「清除」按鈕有效,但我無法使「計算」按鈕正常工作。我現在試圖保持簡單,只需添加兩個框,但我甚至無法讓它工作。
什麼崩潰你得到? – Paulw11
這是一個很長的名單,但基本上單打我的「calculatebutton」按鈕作爲原因 – beans217
這不是原因。特定的行會有特定的例外。 – Paulw11