,我希望它完成NSTimer
中写的initializeTimer()
的执行,然后转到validate()
。但它似乎没有发生。有人可以理解我的错误,因为我无法做到正确......输出是在代码之后给出的......
我也尝试使用fire()但它只执行一次,我需要它继续在用户需要时重复它... 谢谢....
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var progressBar: UIProgressView!
var choice:Int = 0
var tim = NSTimer()
override func viewDidLoad() {
super.viewDidLoad()
println("In ViewDidLoad")
let longPress: UILongPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: "longPressed:")
self.view.addGestureRecognizer(longPress)
}
func longPressed(recognizer: UILongPressGestureRecognizer){
if(recognizer.state == UIGestureRecognizerState.Began){
println("Long Pressed Begin")
initializeTimer()
validate(true, choice: choice)
}
}
func initializeTimer(){
println("In InitializeTimer")
progressBar.setProgress(0, animated: true)
tim = NSTimer.scheduledTimerWithTimeInterval(1, target:self, selector: "setProgress", userInfo: nil, repeats: true)
}
func validate(res: Bool, choice: Int){
println("In validate ")
}
func setProgress(){
println("In setProgress")
tim.invalidate()
}
}
输出:
在ViewDidLoad
中
Long Pressed Begin
在InitializeTimer
中
在validate
中
在设置进度中