-7
我正在做一個ios應用程序,我有一個按鈕,每次點擊時都需要運行大量計算,但按鈕操作僅在第一次運行。誰能幫我這個 ?動作按鈕只能工作一次
這是按鈕的代碼:
@IBAction func Calculate_btn(_ sender: UIButton) {
s2 = 0.0
mintext.text = ""
maxtext.text = ""
avtext.text = ""
if speedUser.text == "" {
let alert = UIAlertController(title: "Error", message: "Give the speed to calculate the new temperature !", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
else if (Int(speedUser.text!)!<0) || (Int(speedUser.text!)!>20) {
let alert = UIAlertController(title: "Error", message: "Give a valid speed : between 0 and 20 Km/h!", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
else {
refTot = ref + ref2
rcfTot = rcf + rcf2
airPermTot = airPermFab + airPermFab2
print("refTot",refTot)
print("rcfTot",rcfTot)
print("airPermTot",airPermTot)
var s2 = (speedUser.text! as NSString).floatValue
Calcul(s: s2, rc: refTot, re: rcfTot, air: airPermTot)
s2 = 0
}
}
'Calcul'在做什麼?它執行任何UI任務嗎? – Mukesh
Calcul正在進行大量物理計算,並將結果放在圖表和4個標籤中@Mukesh –
您是否使用了斷點來證明只有在觸摸按鈕時該方法纔會運行一次(非常不可能)?當你使用調試器遍歷代碼時,你的邏輯是否正確? –