我正在尝试使用新值更新UIView(饼图)。在下面的方法中,我成功地将UIView的pieChart.counter
值设置为我想要的值(并将其打印出来进行测试),但由于某种原因,饼图视图不会使用此值进行更新。
//MARK: Properties
@IBOutlet weak var scoreLabel: UILabel!
@IBOutlet weak var pieChart: CounterView!
@IBOutlet weak var dateLabel: UILabel!
var healthData = HealthData()
let counterView = CounterView()
var scoreInt = 0
override func viewWillAppear(animated: Bool) {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.healthData.updateHealthCharacteristics()
let seconds = 0.1
let delay = seconds * Double(NSEC_PER_SEC) // nanoseconds per seconds
let dispatchTime = dispatch_time(DISPATCH_TIME_NOW, Int64(delay))
dispatch_after(dispatchTime, dispatch_get_main_queue(), {
self.scoreInt = Int(self.healthData.score)
self.scoreLabel.text = String(self.scoreInt)
self.counterView.counter = self.scoreInt
self.pieChart.counter = self.counterView.counter
print("pieChartValue: ", self.pieChart.counter)
let dateString = self.formatDate(self.yesterday!)
self.dateLabel.text = String(dateString)
})
}
在我绘制饼图的类中,我有这段代码:
@IBDesignable class CounterView: UIView {
let possiblePoints = 100
let π:CGFloat = CGFloat(M_PI)
@IBInspectable var outlineColor: UIColor = UIColor.blueColor()
@IBInspectable var counterColor: UIColor = UIColor.orangeColor()
var counter: Int = 0
override func drawRect(rect: CGRect) {
print("foo")
}
}
我已经测试了drawRect
方法,并且它工作正常,但是当我尝试使用我创建的pieChart.counter
实例更新CounterView
时似乎没有触发在我的viewController中。