6

Before iOS 16 picker views take on special behavior when inside forms. They looked like a navigation link which takes you to a new screen where you can choose an option. Since iOS 16 it seems, that this behavior was removed.

Is there a possibility to get the "old" behavior?

e.g. this code

struct ContentView: View {
    @State private var selectedValue = "One"
    let counts = ["One", "Two", "Three"]

    var body: some View {
        NavigationView {
            Form {
                Section {
                    Picker("Selection", selection: $selectedValue) {
                        ForEach(counts, id: \.self) {
                            Text($0)
                        }
                    }
                }
            }
        }
    }
}

results in this behavior (since iOS 16)

picker iOS 16

instead of this (before iOS 16)

Picker Style in Forms before iOS 16

Picker Style in Forms before iOS 16

Thanks!!!

1
  • Great that the old behavior that was available in iOS 15, is no longer available unless you change the deployment target to iOS 16! Commented Nov 16, 2022 at 20:10

2 Answers 2

8

iOS 16 added NavigationLinkPickerStyle which has the pre iOS 16 behavior.

struct ContentView: View {
    @State private var selectedValue = "One"
    let counts = ["One", "Two", "Three"]

    var body: some View {
        NavigationView {
            Form {
                Section {
                    if #available(iOS 16.0, *) {
                        Picker("Selection", selection: $selectedValue) {
                            ForEach(counts, id: \.self) {
                                Text($0)
                            }
                        }
                        .pickerStyle(.navigationLink)
                    } else {
                        Picker("Selection", selection: $selectedValue) {
                            ForEach(counts, id: \.self) {
                                Text($0)
                            }
                        }
                    }
                }
            }
        }
    }
}
Sign up to request clarification or add additional context in comments.

7 Comments

it's giving an error Type "PickerStyle" has no member "navigationLink"
it's the same for me. I get the same error, although I have set everything to iOS 16.
It's weird, because it's in the documentation 🤔
I figured out, that .navigationLink was added in one of the Xcode 14.1 Betas. I'm currently using 14.1 Beta 3 :/
You're right. With 14.1 Beta 3 .navigationLink is available.
|
0

I'm in a similar boat, I'm currently downloading the 14.1 Beta of Xcode, however it WOULD be nice if you could have the menu style picker but also have it display nothing. It's almost as if you already have something selected, but you don't. It causes confusion with the user.

1 Comment

Hey! Welcome to StackOverflow. Your input is helpful but would work better as a comment. Once you get to 50 reputation, you'll be able to make comments. For now, save answers for giving tested, concrete solutions. You can learn more about writing good answers here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.