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      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

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.