ProgressBar仅显示循环结束时的进度。 在这个例子中如何实时更新栏?
@IBAction func btnStart(sender: AnyObject) {
for var xx:Float = 0 ; xx<=1.0; xx=xx+0.00001 {
progressView.setProgress(xx, animated: false)
}
}
@IBOutlet weak var progressLabel: UILabel!
@IBOutlet weak var progressView: UIProgressView!
答案 0 :(得分:1)
UI仅在主循环和当前范围结束时更新
所以试试这个
@IBAction func btnStart(sender: AnyObject) {
NSThread.detachNewThreadSelector("process", toTarget: self, withObject: nil)
}
func process() {
for var xx:Float = 0 ; xx<=1.0; xx=xx+0.00001 {
dispatch_async(dispatch_get_main_queue(), {
progressView.setProgress(xx, animated: false)
})
}
}
@IBOutlet weak var progressLabel: UILabel!
@IBOutlet weak var progressView: UIProgressView!