【发布时间】:2020-04-03 19:50:58
【问题描述】:
我正在尝试在按钮按下操作中更新/设置我的滑块值。
Button(action: {
if self.questionNum == 1{
print("End")
}else{
self.questionNum -= 1
//This line here is where the value is being set.
self.slider.value = self.model.answers[self.questionNum - 1] as! Double
print(self.model.answers)
print(self.slider.value)
self.questionOpacity = 0
self.model.currentQuestion = self.model.questions[self.questionNum - 1]
DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) {
withAnimation(){
self.questionOpacity = 1
}
}
}
}) {
Text("Previous Question")
.font(.system(size: 25))
.fontWeight(.medium)
.foregroundColor(Color.white)
.multilineTextAlignment(.center)
}
滑块值实际上发生了变化,但表盘没有移动或更新以表示新值。我的 Slider 值来自像这样的 Observable 对象:
class SliderVal: ObservableObject {
var didChange = PassthroughSubject<SliderVal,Never>()
var value = 50.0 {
willSet {
print(self.value)
}
}
滑块的默认值设置为中间的 50,有什么方法可以将滑块值设置和更新为存储在数组中的值?输出滑块值实际上给了我正确的结果,那么为什么滑块表盘没有移动/更新?
谢谢
【问题讨论】: