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 String Catalog.

SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!

Localize My App

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.