Reputation:
For some reason the picker in my SwiftUI Form turns gray after I select a value.
My code:
Form {
Section {
TextField("title", text: $title)
Picker(selection: $category, label: Text("category")) {
ForEach(0..<categories.count) { index in
Text(categories[index]).tag(index)
}
}
}
}
Upvotes: 5
Views: 1131
Reputation: 1253
You need to wrap your form inside a NavigationView, the reason being when you tap the picker it will bring up another page, so it needs the navigation view in order to be able to navigate back.
NavigationView {
Form {
Section {
TextField("title", text: $title)
Picker(selection: $category, label: Text("category")) {
ForEach(0..<categories.count) { index in
Text(categories[index]).tag(index)
}
}
}
}
}
Upvotes: 5