Pietro Messineo
Pietro Messineo

Reputation: 837

Open keyboard without clicking on TextField on tvOS - Swift

I'm creating an app and I need to login to it and I don't want to use 2 Text Field for insert Email and Password. What I would wish to achieve is: click on the button "Log in", then it will open the classic full screen keyboard that is usually appearing when you are doing click on UITextField in tvOS.

Can someone please write an example of code on how to invoke the keyboard clicking on a UIButton instead of UITextField? Thanks a lot!

Upvotes: 2

Views: 1900

Answers (2)

Moshe Gottlieb
Moshe Gottlieb

Reputation: 4013

While your UI is questionable, once your first text field finishes editing, you could start the other one.
Set the first text field UITextFieldDelegate to the view controller, and then:

class ViewController: UIViewController , UITextFieldDelegate{

    @IBOutlet weak var tf2: UITextField!
    @IBOutlet weak var tf1: UITextField!

    @IBAction func click() {
        tf1.becomeFirstResponder()
    }

    func textFieldDidEndEditing(_ textField: UITextField) {
        if (textField == tf1){
            tf2.becomeFirstResponder()
        }
    }

}

Upvotes: 2

henrik-dmg
henrik-dmg

Reputation: 1493

If you want a UITextField to open up the keyboard without the user having to tap on it, you can use yourTextField.becomeFirstResponder(). I don't think you can present the keyboard without any associated input view

Upvotes: 1

Related Questions