-3
嗨Im新的快速編程。我想獲得一個文本字段的輸入,將其轉換爲一個int然後使用該int(減少它)。這裏是我的代碼:將TextField轉換爲Var Int(swift)
@IBOutlet weak var minutes: UITextField!
@IBOutlet weak var seconds: UITextField!
@IBOutlet weak var label_Timer: UILabel!
@IBAction func btn_Timer(_ sender: UITextField) {
var min:Int = Int(minutes.text!)
var sec:Int = Int(seconds.text!)
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(ViewController.timerRunning), userInfo: nil, repeats: true)
}
func timerRunning(){
sec -= 1
//operate on min and sec here
}
好的,您真正的問題是什麼?您發佈的代碼有什麼問題? – rmaddy
提示:一對大括號就像一個封閉的房間。在該範圍內的任何聲明變量(* room *)在外面都不可見。 – vadian
我想將分鐘和秒(UItextField)轉換爲int變量,所以我可以在func timer中操作它們運行 –