UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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 Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot 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.