UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Picker Click and go to another UIView?

Forums > SwiftUI

I would like to click on the row and go to another UIView named Location Any help would be appriciated. Robert

struct ContentView: View { var storyPicker = ["Montreal","Quebec", "Boston", "Sacramento", "San Francisco"]

@State private var selectedStory = 0

var body: some View {

    VStack {
        Picker(selection: $selectedStory, label: Text("Select Your Story")) {
            ForEach(0 ..< storyPicker.count) {

                Text(self.storyPicker[$0])
            }
            Text(" You Have Selected: \(storyPicker[selectedStory])")
        }

// .onReceive(self, perform: { // Location()

    }
}

}

3      

Try this

struct ContentView: View {
    var storyPicker = ["Select City","Montreal","Quebec", "Boston", "Sacramento", "San Francisco"]
    @State private var selectedStory = 0
    @State private var isActive = false

    var body: some View {
        NavigationView {
            VStack {
                Text(" You Have Selected: \(storyPicker[selectedStory])")

                Picker(selection: $selectedStory, label: Text("Select Your Story")) {
                    ForEach(0 ..< storyPicker.count) { story in
                        NavigationLink(storyPicker[story], destination: Text(storyPicker[story]), isActive: $isActive)
                    }
                }
                .onChange(of: selectedStory, perform: { _ in
                    isActive.toggle()
                })
            }
        }
    }
}

3      

Thank you for your code, and it does work as you have wrote it. What is needed is the ability to go to the , Location()

Thank you for your assisting me. Sincerely, Robert

3      

Hi Robert

  1. What is Location()?

  2. My understanding that you what to go to a View if you put that in destination: instead of Text(storyPicker[story]) this will go to the view of the "location" selected.

Nigel

3      

Thank you for your code, and it does work as you have wrote it. But what I need is upon the selection I need it to go to, Location()

Thank you for your assisting me. Sincerely, Robert

3      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.