TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

WeSplit - SwiftUI Picker Bug?

Forums > 100 Days of SwiftUI

Hello all.

UIKit Curmudgeon here coming in to learn SwiftUI in this 100 Days course. I just completed WeSplit, and a part of the "Challenge" section stuck out to me. So I wanted to know if anyone else had faced it. Apologies if it's been asked before.

In essence, changing the picker into a .pickerStyle(.navigationLink) seems to not automatically scroll to the selected item when showing the detail page.

If I remove that modifier, and use the default menu popup, then it will automatically scroll to the selected item.

Am I missing something? Is there something else I need to add?

2      

I don't have an answer for you.

But here's a code snip that illustrates your question. Maybe someone else can explore a proper response?

struct PickerExample: View {
    // 42 The Answer to the Ultimate Question of Life, The Universe, and Everything
    @State private var mySelection = 42
    var body: some View {
        NavigationStack {
            Text("You selected option # \(mySelection)")
                .font(.title).foregroundStyle(mySelection == 42 ? .indigo : .black)
            Form {
                // ==============================================
                // This picker will show your selection centered with
                // equal number of options above and below it.
                Section {
                    Picker(selection: $mySelection, label: Text("Inline Picker")) {
                        ForEach(1..<50) { option in
                            Text(String(option)).tag(option)
                        }
                    }
                }
                // ==============================================
                // This picker shows the first dozen or so options.
                // You have to scroll several screens to find your selection.
                // This is NOT desired behaviour.
                Section {
                    Picker(selection: $mySelection, label: Text("Navigation Style")) {
                        ForEach(0..<50) { option in
                            Text(String(option)).tag(option)
                        }
                    }
                    .pickerStyle(.navigationLink).accentColor(.red)
                }
            }
            .navigationTitle("Picker Example")
        }
    }
}

2      

Hacking with Swift is sponsored by Superwall.

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

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

Reply to this topic…

You need to create an account or log in to reply.

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.