gur*_*gui 2 swift swiftui ios14 xcode12
我需要在工作表内的表单中使用选择器。但这是行不通的。如果我单击选择器,我将无法选择元素。
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)
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这里有什么建议吗?
它需要NavigationView,即
.sheet(isPresented: $showSheet, content: {
NavigationView {
SecondView()
}
})
Run Code Online (Sandbox Code Playgroud)
另一种方法是直接Form嵌入到.NavigationViewSecondView
| 归档时间: |
|
| 查看次数: |
1151 次 |
| 最近记录: |