我有以下代码:
var gaugeView1 = CHCircleGaugeView(frame: CGRectMake(0, 0, 280, 280))
self.mainGaugeView.addSubview(gaugeView1)
gaugeView1.setTitleValue("TODAY", hideLabel: false);
var query = PFQuery(className: "Values")
query.findObjectsInBackgroundWithBlock({ (objects, error) in
if let valObjects = objects as? [PFObject] {
for val in valObjects {
if let average = val.objectForKey("AVERAGE") as? Double {
dispatch_sync(dispatch_get_main_queue(), { () -> Void in
gaugeView1.setValue(average, hideLabel: false, animated: true)
})
}
}
}
})
问题在于
gaugeView1.setValue()
实际并未更新该值。最初,我没有让它在主线程上运行,然后不幸地添加到了
dispatch_sync()
中,但这并不能解决问题。 最佳答案
您应该使用dispatch_async
而不是dispatch_sync
:
dispatch_async(dispatch_get_main_queue(), { () -> Void in
gaugeView1.setValue(average, hideLabel: false, animated: true)
})