我需要在工作表内的表单中使用选择器。但这是行不通的。如果单击选择器,则不会进入元素选择。
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)
}
}
}
}
这里有什么建议吗?
答案 0 :(得分:1)
它需要NavigationView
,即
.sheet(isPresented: $showSheet, content: {
NavigationView {
SecondView()
}
})
替代方法是将Form
嵌入NavigationView
中的SecondView
中。