UILabel 值未在 Parse 块内更新

UILabel value not updating inside Parse block

我有以下代码:

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)
})