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

Project 1- decimal pad and adding a segmented control

Forums > 100 Days of SwiftUI

Im up to the part where im adding a segmented control for the tip percentages and ive done everything he has shown but its not showing up. Can someone tell me what im doing wrong? also my decimal pad isnt showingup either.

import SwiftUI

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

let tipPercentages = [10, 15, 20, 25, 0]

var body: some View {
    NavigationView {
    Form {
        Section {
            TextField("Amount", text: $checkAmount)
                .keyboardType(.decimalPad)
        }

        Picker("Number of people", selection: $numberOfPeople) {
            ForEach(2 ..< 100) {
                Text("\($0) people")
            }
            Section {
                Picker("Tip percentage", selection: $tipPercentage) {
                    ForEach(0 ..< tipPercentages.count) {
                        Text("\(self.tipPercentages[$0])%")
                    }
                }
            .pickerStyle(SegmentedPickerStyle())
            }
        }

        Section {
            Text("$\(checkAmount)")
        }
    }
    .navigationBarTitle("WeSplit")

    }
}

}

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

2      

First Keyboard not showing. I assume you on simulator (not real device). When select field do Cmd-K and keyboard will appear. On real devices this will happen automatically.

Your Tip Picker is inside the first (Number of people) picker it need to be after it

        Picker("Number of people", selection: $numberOfPeople) {
            ForEach(2 ..< 100) {
                Text("\($0) people")
            }
          } \\ <- add this one

          Section {
              Picker("Tip percentage", selection: $tipPercentage) {
                  ForEach(0 ..< tipPercentages.count) {
                      Text("\(self.tipPercentages[$0])%")
                  }
              }
              .pickerStyle(SegmentedPickerStyle())
          }

      } \\ <- delete this one

4      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.