NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

Pickerstyle .navigationLink does not work

Forums > SwiftUI

Never mind this post, the instructor addressed the issue. You need to put the picker in a NavigationView.

I'm on day 17 of 100 days with SwiftUI creating pickers in a form. I coded it just like the instructor but I got the menu picker instead of the navigationlink. The menu picker is blue while the default picker is grey. I tried adjusting the pickerstyle to .navigationLink but its not adjustable. It stays fixed on 4 people. Here is my code, tell me what I am doing wrong.

I wish I could figure out how to add photos to thread. Text only sucks.

https://www.dropbox.com/s/6nmz4xf6gjkshc6/Screenshot%202023-05-29%20at%203.33.36%20PM.png?dl=0

import SwiftUI

struct ContentView: View
{
    @State private var checkAmount = 0.0
    @State private var numberOfPeople = 2
    @State private var tipPercentage = 20

    let tipPercentages = [10, 15, 20, 25, 0]
    var body: some View
    {
        Form
        {
            Section
            {
                TextField("Amount", value: $checkAmount, format: .currency(code: Locale.current.currency?.identifier ?? "USD"))
                    .keyboardType(.decimalPad)

                Picker("Number of people", selection: $numberOfPeople)
                {
                    ForEach(2..<100)
                    {
                        Text("\($0) people")
                    }
                }
                .pickerStyle(.navigationLink)
            }

            Section
            {
                Text(checkAmount, format: .currency(code: Locale.current.currency?.identifier ?? "USD"))
            }
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

   

I think you need NavigationView before the Form. Or wrap the Form in NavigationView{Form {} }. Alternatively try the .menu or .wheel. Plenty options to suit your taste.

If you press the insert image you should be able to upload an image.

   

@morpheus addresses a visual issue:

I wish I could figure out how to add photos to thread. Text only sucks.

See -> How to add graphics to your post

or See -> Another Handy Guide

   

Hacking with Swift is sponsored by Judo

SPONSORED Let’s face it, SwiftUI previews are limited, slow, and painful. Judo takes a different approach to building visually—think Interface Builder for SwiftUI. Build your interface in a completely visual canvas, then drag and drop into your Xcode project and wire up button clicks to custom code. Download the Mac App and start your free trial today!

Try now

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.