user3574603
user3574603

Reputation: 3618

SwiftUI: Why doesn't picker display?

I'm following this tutorial to implement a picker using SwiftUI.

The tutorial preview looks like this:

picker screenshot

Whereas I have no picker in my preview:

no picker

Why doesn't my code display a picker?

Here's my view:

import SwiftUI

struct CheckoutView: View {
    @EnvironmentObject var order: Order
    @State private var paymentType = "Cash"

    let paymentTypes = ["Cash", "Credit Card", "iDine Points"]

    var body: some View {
        VStack {
            Section {
                Picker("How do you want to pay?", selection: $paymentType) {
                    ForEach(paymentTypes, id: \.self) {
                        Text($0)
                    }
                }
            }
        }
        .navigationTitle("Payment")
        .navigationBarTitleDisplayMode(.inline)
    }
}

struct CheckoutView_Previews: PreviewProvider {
    static var previews: some View {
        CheckoutView()
            .environmentObject(Order())
    }
}

(I'm using Xcode 13.3)

Upvotes: 0

Views: 316

Answers (1)

lorem ipsum
lorem ipsum

Reputation: 29242

Likely an older video, if you set the pickerStyle to .wheel

Picker("How do you want to pay?", selection: $paymentType) {
    //Your code
}.pickerStyle(.wheel)

you will get that look. Right now it is likely a menu style. When you don't set the type Apple can pick which style to use.

Upvotes: 1

Related Questions