[英]How can I navigate to different views?
I am learning to use Swiftui and I need your help.我正在学习使用 Swiftui,我需要你的帮助。 The following pickers are present in my project:
我的项目中存在以下选择器:
Picker(selection: $selectedChoose, label: Text("Cosa ti serve?")) {
ForEach(0 ..< choose.count) {
Text(self.choose[$0]).tag($0)
}
}.pickerStyle(SegmentedPickerStyle())
//WheelPickerStyle
Picker(selection: $selectedCountry, label: Text("Città")) {
ForEach(0 ..< country.count) {
Text(self.country[$0]).tag($0)
}
}
Picker(selection: $selectedAppartamento, label: Text("Tipo appartamento")) {
ForEach(0 ..< appartamento.count) {
Text(self.appartamento[$0]).tag($0)
}
}
Picker(selection: $selectedCamera, label: Text("Tipo camera")) {
ForEach(0 ..< camera.count) {
Text(self.camera[$0]).tag($0)
}
}
At the end of the View, I have the following Text to which I will add the NavigationLink:在视图的末尾,我有以下文本,我将向其中添加 NavigationLink:
Text("Mostra annunci")
.font(Font.custom("Helvetica Neue", size: 15))
.foregroundColor(.white)
.frame(width: 150, height: 30).foregroundColor(Color.white)
.background(Color(red: 0.649, green: 0.18, blue: 0.117)).cornerRadius(10).padding(15)
Is it possible to link user choices with different views?是否可以将用户选择与不同的视图联系起来? I mean, if a user selects a different city, room type and type of apartments, how can I link these choices to different views?
我的意思是,如果用户选择不同的城市、房间类型和公寓类型,我如何将这些选择链接到不同的视图? Each view should show results based on the different choices made by the user in the pickers above.
每个视图都应该根据用户在上面的选择器中做出的不同选择来显示结果。 How can I do that?
我怎样才能做到这一点?
Thank you in advance:)先感谢您:)
you can popup new views using the.sheet(...).您可以使用.sheet(...) 弹出新视图。 The restriction is that you can only have one of those.
限制是您只能拥有其中之一。 So you would have to do something like this:
所以你必须做这样的事情:
.sheet(isPresented: $showSheet) {
if self.selectedCountry == "myCountry" {
Text("myCountry")
}
else if self.selectedCountry == "yourCountry" {
Text("yourCountry")
}
... lots of other if else
In your case I would reconsider the whole structure.在你的情况下,我会重新考虑整个结构。 Use just one sheet option and pass in the choices the user made.
仅使用一个工作表选项并传递用户所做的选择。 And inside the new view present the data as chosen.
在新视图中显示所选数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.