TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

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()
    }
}

2      

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.

2      

@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

2      

Hacking with Swift is sponsored by Superwall.

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

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.