Does anyone have a fix for this? I have a Picker
in my List
that doesn't respond to any user input and is greyed out, but if I move it out of the List
and into a VStack
it functions normally.
The majority of answers I've found to this question all say that the Picker
needs to be in a Form
to work (which I don't understand since it works fine in a VStack
), or that its a bug in which it only works on a physical device, which I've also tested on and gotten the same result.
I'll provide a screenshot as well as the code I'm using below
import SwiftUI
struct SettingsView: View {
@Binding var age : Int
var body: some View {
VStack(alignment: .leading){
List{
Picker("Your age", selection: $age) {
ForEach(1...100, id: \.self) { number in
Text("\(number)")
}
}
}
}
}
You must embed your List
inside a NavigationView
, so you can actually "navigate" from "Your age" to the list of Int
s.
Just add one additional layer, as shown below:
var body: some View {
VStack(alignment: .leading){
NavigationView { // This is needed to navigate to the ForEach
List {
Picker("Your age", selection: $age) {
ForEach(1..<101) { number in
Text("\(number)")
}
}
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With