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

WeSplit Keyboard Issue

Forums > 100 Days of SwiftUI

I copied codes from github. But the keyboard doesnt appear.

3      

Do you mean in the simulator?

if so, when TextField is selected, do CMD+K to get the keyboard on device

4      

I'm having this problem also - running XCode 13.1 and following the WeSplit tutorial. CMD+K does not show the keyboard (iOS 15.0 on iPhone 13 Pro simulator). I can type using the Mac keyboard. None of the Simulator's I/O or Keyboard functions seem to make a difference.

3      

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!

Could you show or link your code? I will try to run it on my machine too. I did not had any issues for the keyboard when I did the exercise.

3      

Here you go - thanks!

//
//  ContentView.swift
//  WeSplit
//
//  Created by Michael Hackney on 11/11/21.
//

import SwiftUI

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

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

    var totalPerPerson: Double {
        let peopleCount = Double(numberOfPeople + 2)
        let tipSelection = Double(tipPercentage)

        let tipValue = checkAmount / 100 * tipSelection
        let grandTotal = checkAmount + tipValue
        let amountPerPerson = grandTotal / peopleCount
        return amountPerPerson
    }

    var body: some View {
        NavigationView {
            Form {
                Section {
                    TextField("Amount", value: $checkAmount, format: .currency(code: Locale.current.currencyCode ?? "USD"))
                        .keyboardType(.decimalPad)
                        .focused($amountIsFocused)

                    Picker("Number of people", selection: $numberOfPeople) {
                        ForEach(2..<100) {
                            Text("\($0) people")
                        }
                    }
                }
                Section {
                    Picker("Tip percentage", selection: $tipPercentage) {
                        ForEach(tipPercentages, id: \.self) {
                            Text($0, format: .percent)
                        }
                    }
                    .pickerStyle(.segmented)
                } header: {
                    Text("How much tip do you want to leave?")
                }

                Section {
                    Text(totalPerPerson, format: .currency(code: Locale.current.currencyCode ?? "USD"))

                }
            }
            .navigationTitle("WeSplit")
            .toolbar {
                ToolbarItemGroup(placement: .keyboard) {
                    Spacer()
                    Button("Done") {
                        amountIsFocused = false
                    }
                }
            }
        }
    }
}

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

3      

Well, I see there are simulator errors that I hadn't notice:

2021-11-11 12:54:30.626600-0500 WeSplit[6888:4331387] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x6000005072a0 'BIB_Leading_Leading' H:|-(0)-[_UIModernBarButton:0x7f9ece01e050]   (active, names: '|':_UIButtonBarButton:0x7f9ece01abd0 )>",
    "<NSLayoutConstraint:0x600000500050 'UINav_static_button_horiz_position' _UIModernBarButton:0x7f9ece01e050.leading == UILayoutGuide:0x600001f5cfc0'UIViewLayoutMarginsGuide'.leading   (active)>",
    "<NSLayoutConstraint:0x6000005000a0 'UINavItemContentGuide-leading' H:[_UIButtonBarButton:0x7f9ece01abd0]-(6)-[UILayoutGuide:0x600001f5cee0'UINavigationBarItemContentLayoutGuide']   (active)>",
    "<NSLayoutConstraint:0x6000005053b0 'UINavItemContentGuide-trailing' UILayoutGuide:0x600001f5cee0'UINavigationBarItemContentLayoutGuide'.trailing == _UINavigationBarContentView:0x7f9ece019000.trailing   (active)>",
    "<NSLayoutConstraint:0x60000051f480 'UIView-Encapsulated-Layout-Width' _UINavigationBarContentView:0x7f9ece019000.width == 0   (active)>",
    "<NSLayoutConstraint:0x600000505270 'UIView-leftMargin-guide-constraint' H:|-(8)-[UILayoutGuide:0x600001f5cfc0'UIViewLayoutMarginsGuide'](LTR)   (active, names: '|':_UINavigationBarContentView:0x7f9ece019000 )>"
)

3      

It works both on my simulator and in my physical iphone 13 mini. Without any issues. Could you try to update your version of xcode maybe? You could also make sure the project is has a iOs 15.0 version as target.

3      

As an additional idea, Have you tried with a diferent simulator? like a iphone 12 pro? I haven't seen any error in the simulator in my machine.

3      

Interesting. I have tried all of your suggestions. I'll restart XCode and see what happens. I have not tried running on my physical device yet.

3      

When I try iPhone 11 Pro, the keyboard now shows up (numeric) with the Done button. I still get the layout errors I posted above. And if I switch back to 13 Pro, the keyboard no longer appears. But normal iPhone 13 simulator works!

3      

13 Pro Max also works. In all cases that work I also get the layout constraint issues I show above. So far, only iPhone 13 Pro does not show the keyboard! I own a physical 13 Pro but I can't imagine that there is any correlation.

3      

Spoke too soon, the behavior of the keyboard on the simulators that work is odd. Once I dismiss the keyboard, it won't reappear with focus in the textedit field. And now, the 13 Pro Max is not showing the keyboard when restarted (even with quitting the Simulator).

Something very odd is going on.

3      

Ok, I had some issues with the simulator a while ago. I ended up erasing the data of the simulators and regenerated it again. (Also to clean some space in the hard drive)

You sould try following this guide here: https://www.dev2qa.com/how-to-fix-xcode-ios-simulator-app-do-not-display-keyboard-automatically-error/

I usually clean the xcode caches with a tool like CleanMyMacX and the simulator data from time to time too.

Hope this works!

3      

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!

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.