首页 > 解决方案 > 在工作表内的表单中使用选取器不起作用

问题描述

我需要在工作表内的表单中使用选择器。但这不起作用。如果我单击选择器,我不会进入元素的选择。

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)
            }
        }
    }
}

这里有什么建议吗?

标签: swiftswiftuiios14xcode12

解决方案


它需要NavigationView,即

    .sheet(isPresented: $showSheet, content: {
        NavigationView {
           SecondView()
        }
    })

替代是直接嵌入Form在.NavigationViewSecondView


推荐阅读