Hide Keyboard in app

Hi All,

I have just started to learn swiftui and just messing around.

I have created a form got a couple of text boxes in it with decimal keyboard and also a picker in the form

The problem I have is that when you click in the text box you can’t make the keypad go, is there a way to put a done button on the keypad?

@Seesor Welcome to the community!

What I typically do is something like this, although there are other solutions.

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
           hideKeyboard()
       }

    
    func hideKeyboard() {
        yourTextField.resignFirstResponder()
    }

You can also do this when the user taps return on the keyboard:

//Add the delegate to the class
UITextFieldDelegate

//In viewDidLoad add the following
//Delegate need to connect return key on keyboard
        addField.delegate = self



func textFieldShouldReturn(_ taskFiled: UITextField) -> Bool {
        self.view.endEditing(true)
        
        if yourTextField!.isEmpty {
            //Empty so close
            taskFiled.text = ""
            
            return true
        }
        
        //Do whatever the field does here.
        return true
    }

Blessings,
—Mark

Thanks Mark I will give this a try