简体   繁体   中英

How can I navigate to different views?

I am learning to use Swiftui and I need your help. 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:

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(...). 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM