我如何导航到不同的视图?

问题描述 投票:0回答:1

我正在学习使用Swiftui,需要您的帮助。我的项目中存在以下选择器:

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

在视图末尾,我将在下面的文本中添加导航链接:

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)

是否可以将用户选择与不同的视图关联?我的意思是,如果用户选择其他城市,房间类型和公寓类型,该如何将这些选择链接到不同的视图?每个视图都应根据用户在上方选择器中做出的不同选择显示结果。我该怎么办?

提前谢谢您:)

swiftui user-input picker navigationlink pickerview
1个回答
0
投票

您可以使用.sheet(...)弹出新视图。限制是您只能拥有其中之一。因此,您必须执行以下操作:

        .sheet(isPresented: $showSheet) {
            if self.selectedCountry == "myCountry" {
                Text("myCountry")
            }
            else if self.selectedCountry == "yourCountry" {
                Text("yourCountry")
            }
            ... lots of other if else

在您的情况下,我将重新考虑整个结构。仅使用一张纸选项传递用户做出的选择。并在新视图中显示所选的数据。

© www.soinside.com 2019 - 2024. All rights reserved.