SwiftUI - 无法在表单中向选择器视图添加修饰符
SwiftUI - Can't add modifiers to Picker View within a form
我目前正在处理#hackingwithswift 的项目 4。我遇到无法从表单视图中更改选择器样式的问题。
这是我正在处理的一小段代码。请假设其余代码是正确的。无论我在 .pickerStyle()
中输入什么修饰符,我总是得到错误:
Type 'WheelPickerStyle.Type' cannot conform to 'PickerStyle'; only
struct/enum/class types can conform to protocols
NavigationView{
Form{
Section(header: Text("When do you want to wake up?") .font(.headline)) {
DatePicker("Please enter a time", selection: $wakeUp, displayedComponents: .hourAndMinute)
.datePickerStyle(WheelDatePickerStyle())
.labelsHidden()
}
Section(header: Text("Desired amount of sleep")
.font(.headline)) {
Stepper(value: $sleepAmount, in: 4...12, step: 0.25) {
Text("\(sleepAmount, specifier: "%g") hours")
}
}
Section(header: Text("Daily coffee intake")
.font(.headline)) {
Picker("Number of coffees had in a day", selection: $coffeeAmount) {
Text("1")
Text("2")
Text("3")
}
.pickerStyle(WheelPickerStyle)
}
谁能帮帮我?请解释我做错了什么,我是初学者!
提前致谢!
在你的代码中
Picker("Number of coffees had in a day", selection: $coffeeAmount) {
Text("1")
Text("2")
Text("3")
}
.pickerStyle(WheelPickerStyle)
}
您应该使用 WheelPickerStyle()
而不是 WheelPickerStyle
我目前正在处理#hackingwithswift 的项目 4。我遇到无法从表单视图中更改选择器样式的问题。
这是我正在处理的一小段代码。请假设其余代码是正确的。无论我在 .pickerStyle()
中输入什么修饰符,我总是得到错误:
Type 'WheelPickerStyle.Type' cannot conform to 'PickerStyle'; only struct/enum/class types can conform to protocols
NavigationView{
Form{
Section(header: Text("When do you want to wake up?") .font(.headline)) {
DatePicker("Please enter a time", selection: $wakeUp, displayedComponents: .hourAndMinute)
.datePickerStyle(WheelDatePickerStyle())
.labelsHidden()
}
Section(header: Text("Desired amount of sleep")
.font(.headline)) {
Stepper(value: $sleepAmount, in: 4...12, step: 0.25) {
Text("\(sleepAmount, specifier: "%g") hours")
}
}
Section(header: Text("Daily coffee intake")
.font(.headline)) {
Picker("Number of coffees had in a day", selection: $coffeeAmount) {
Text("1")
Text("2")
Text("3")
}
.pickerStyle(WheelPickerStyle)
}
谁能帮帮我?请解释我做错了什么,我是初学者!
提前致谢!
在你的代码中
Picker("Number of coffees had in a day", selection: $coffeeAmount) {
Text("1")
Text("2")
Text("3")
}
.pickerStyle(WheelPickerStyle)
}
您应该使用 WheelPickerStyle()
而不是 WheelPickerStyle