Reputation: 14694
I need to use a picker in a form inside a sheet. But this does not work. If I click on the picker I get not into the selection of the Elements.
struct ContentView: View {
@State private var showSheet = false
var body: some View {
Button("Sheet", action: {
showSheet.toggle()
})
.sheet(isPresented: $showSheet, content: {
SecondView()
})
}
}
struct SecondView: View {
var body: some View {
Form {
Picker(selection: .constant(1), label: Text("Picker")) {
Text("1").tag(1)
Text("2").tag(2)
}
}
}
}
Any suggestions here?
Upvotes: 4
Views: 1477
Reputation: 258107
It requires NavigationView
, ie
.sheet(isPresented: $showSheet, content: {
NavigationView {
SecondView()
}
})
alternate is to embed Form
in NavigationView
directly in SecondView
.
Upvotes: 7