skip to Main Content

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!!!

2

Answers


  1. 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)
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    
    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search