简体   繁体   English

SwiftUI - 无法在表单中向 Picker View 添加修饰符

[英]SwiftUI - Can't add modifiers to Picker View within a form

I'm currently working on Project 4 of #hackingwithswift.我目前正在#hackingwithswift 的项目 4 上工作。 I'm having the problem of not being able to change the style of my picker from within a form view.我遇到了无法从表单视图中更改选择器样式的问题。

Here's a little snippet of the code I'm working on.这是我正在处理的代码的一小段。 Please assume the rest of the code is correct.请假设其余的代码是正确的。 No matter what modifier I put in .pickerStyle() , I always get the error:无论我在.pickerStyle()放入什么修饰符,我总是会收到错误消息:

Type 'WheelPickerStyle.Type' cannot conform to 'PickerStyle';类型 'WheelPickerStyle.Type' 不能符合 '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)
                    }

Can anyone help me out?谁能帮我吗? Please explain what I'm doing wrong, I'm a beginner!请解释我做错了什么,我是初学者!

Thanks in advance!提前致谢!

In your code在你的代码中

Picker("Number of coffees had in a day", selection: $coffeeAmount) {
                            Text("1")
                            Text("2")
                            Text("3")
                        }
                    .pickerStyle(WheelPickerStyle)
                    }

You should use WheelPickerStyle() instead of WheelPickerStyle您应该使用WheelPickerStyle()而不是WheelPickerStyle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM