-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 –
您是否使用了断点来证明只有在触摸按钮时该方法才会运行一次(非常不可能)?当你使用调试器遍历代码时,你的逻辑是否正确? –