I have a picker on my view but it's not selectable unless I replace my VStack for a NavigationView. However I cant have a NavigationView on this page, otherwise it brakes other parts.
What's the solution for that ? Thx
VStack {
Picker
}
I have a picker on my view but it's not selectable unless I replace my VStack for a NavigationView. However I cant have a NavigationView on this page, otherwise it brakes other parts.
What's the solution for that ? Thx
VStack {
Picker
}
I don't understand your point (may be because you did not show code).
struct ContentView: View {
var colors = ["Red", "Green", "Blue", "Tartan"]
@State private var selectedColor = "Red"
var body: some View {
// VStack { // I remove VStack voluntarily
HStack {
Text("Please choose a color")
Picker("", selection: $selectedColor) {
ForEach(colors, id: \.self) {
Text($0)
}
}
// }
Text("You selected: \(selectedColor)")
}
}
}
struct ContentView: View {
var colors = ["Red", "Green", "Blue", "Tartan"]
@State private var selectedColor = "Red"
var body: some View {
VStack {
HStack {
Text("Please choose a color")
Picker("", selection: $selectedColor) {
ForEach(colors, id: \.self) {
Text($0)
}
}
}
Text("You selected: \(selectedColor)")
}
}
}
Note : text does not show in Picker
read: h t t p s : / / w w w.hackingwithswift.com/forums/swiftui/swiftui-xcode-12-2-picker-no-longer-shows-label/4809
Here what I've figured out:
Form {
Picker("Choose a number", selection: $selection) {
ForEach(0 ..< data.count, id: \.self) { index in
Text(data[index])
}
}
}
NavigationView {
Form {
Picker("Choose a number", selection: $selection) {
ForEach(0 ..< data.count, id: \.self) { index in
Text(data[index])
}
}
}
However for my current design, I can't have a NavigationView on this View. Is there a solution for that ? Thx
If a picker is inside a Form, it's going to be frozen and not selectable
Do you need a Form or not ? You didn't say in your OP.
If you search you will find it is a known bug in SwiftUI.
https://stackoverflow.com/questions/66275021/picker-appears-disabled-inside-a-form-bug/66275172
So, all you can do:
Found a solution. Replace the form with ScrollView instead of NavigationView and the picker will work :)