swift - 在工作表内的表单中使用选取器不起作用
问题描述
我需要在工作表内的表单中使用选择器。但这不起作用。如果我单击选择器,我不会进入元素的选择。
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
推荐阅读
- animation - SVG动画在完成后放回
- flutter - 如何将指定的图像资产添加到 pubspec,然后将图像加载到 AssetImage 以供应用程序呈现?
- lua - lua 5.1中的uint64到十六进制
- android - Android:在 TextView 中将肤色应用于表情符号
- ruby-on-rails - 如何从 ruby on rails 中的 csv 文件中读取 csv 文件数据
- c# - 我正在从 gridview 中删除行,但表中的所有数据都已删除
- javascript - 如何将下一个和上一个按钮添加到我的反应幻灯片网站
- android - 上次更新 android studio 中的数据绑定
- sql - Snowflake:SQL Query 用于从同一个或多个表中识别具有相同 ID 的所有不同用户
- python - 打印可被 3 或 5 整除的数字的计数