在 Sheet 内的表单中使用选取器不起作用
Using a Picker in a Form inside an Sheet does not work
我需要在 sheet 内的表单中使用选择器。但这不起作用。如果我单击选择器,我将不会选择元素。
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)
}
}
}
}
这里有什么建议吗?
需要NavigationView
,即
.sheet(isPresented: $showSheet, content: {
NavigationView {
SecondView()
}
})
替代方法是将 Form
直接嵌入 NavigationView
中 SecondView
。
我需要在 sheet 内的表单中使用选择器。但这不起作用。如果我单击选择器,我将不会选择元素。
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)
}
}
}
}
这里有什么建议吗?
需要NavigationView
,即
.sheet(isPresented: $showSheet, content: {
NavigationView {
SecondView()
}
})
替代方法是将 Form
直接嵌入 NavigationView
中 SecondView
。