我试图利用动态数据。我使用MotionKit Framework创建了一个测试应用。 print(testString)
以一秒的间隔正确地将x
变量打印到控制台。但我的testLabel不会更新一次。
import UIKit
import MotionKit
class ViewController: UIViewController {
@IBOutlet weak var testLabel: UILabel!
let motionKit = MotionKit()
override func viewDidLoad() {
super.viewDidLoad()
motionKit.getAccelerometerValues(1.0) { (x, y, z) -> () in
let testString = String(x)
self.testLabel.text = testString
print(testString)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
我错过了什么?非常感谢帮助。
答案 0 :(得分:2)
只需将文本字段代码包装在dispatch_async
中dispatch_async(dispatch_get_main_queue(), ^{
self.testLabel.text = testString
});