gpt4 book ai didi

ios - UIView 不更新,即使它的值似乎在代码中发生了更改

转载 作者:行者123 更新时间:2023-11-30 13:53:47 25 4
gpt4 key购买 nike

我正在尝试使用新值更新 UIView(饼图)。在下面的方法中,我成功地将 UIView 的 pieChart.counter 值设置为我想要的值(并将其打印出来进行测试),但由于某种原因,饼图 View 不会使用该值更新。

//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 时,它似乎没有触发我在 viewController 中创建的 CounterView

最佳答案

要重绘某些 View ,您只需调用 setNeedsDisplay 即可。请参阅Drawing Concepts in iOS了解有关什么可以触发重绘的更多信息。

关于ios - UIView 不更新,即使它的值似乎在代码中发生了更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33925186/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com