选择一个选择器值以指向文本字段,SwiftUI [英] Selecting a picker value to lead to a text field, SwiftUI
问题描述
我正在尝试在我的应用中实现一项功能.
Im trying to implement a feature in my app.
当我点击我的选择器时:
When I click on my picker:
Picker(selection: $profileViewModel.education,
label: Text("Education Level")) {
ForEach(Education.levels, id: \.self) { level in
Text(level).tag(level)
}
}
这会将我带到一个屏幕,然后我选择值(这很好 - 它按预期工作)
This takes me to a screen and then I select the value (this is fine - it works as expected)
我如何选择值,然后让我假设另一个屏幕,以便我可以填写有关所选值的更多详细信息.
How could I select the value which then takes my to let's say another screen so I can fill in more details regarding the selected value.
例如,上面的选择器有一个值来选择教育级别,选择它后,我怎么能得到一个动作表/另一个屏幕,这样我就可以在那里有一个文本字段来保存这些额外的数据,或者一旦选择完成后,会出现一个文本字段供我保存一些额外的数据,然后单击一个按钮将我带到选择器的原始屏幕(希望有意义)?
For example the above picker has a values to select eduction level, after selecting it, how could I get an action sheet/another screen appear so I can have a text field there to save this extra data to or once the selection is made, a text field appears for me to save some extra data, and then clicking a button which would take me to the original screen of the picker (hope that makes sense)?
我曾尝试在线研究与此类似的问题,但似乎找不到/或者您是否可以指出我应该研究的方向?
I've tried researching online for a problem similar to this but can't seem to find one/or if you can point me in the direction of what I should be looking into?.
尝试了以下方法:
推荐答案
如果我正确理解你的场景,这里是一种可能的方法(使用 Xcode 12/iOS 14 进行复制测试)
If I correctly understood your scenario here is a possible approach (replication tested with Xcode 12 / iOS 14)
Picker(selection: $profileViewModel.education,
label: Text("Education Level")) {
ForEach(Education.levels, id: \.self) { level in
Text(level).tag(level)
}
}
.onChange(of: profileViewModel.education) { _ in
DispatchQueue.main.async {
self.showSheet = true
}
}
.sheet(isPresented: $showSheet) {
// put here your text editor or anything
Text("Editor for \(profileViewModel.education)")
}
这篇关于选择一个选择器值以指向文本字段,SwiftUI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!