0

I'm making an app and I want the user to be able to input text without having them actually click on a UITextField (have it open after the game ends for a scoreboard), is there some way to do that?

2 Answers2

1

Yes, just:

<#your_text_field#>.becomeFirstResponder()

after the game ends.

This will produce the "same" effect as a tap on the UITextField. If this is on a new UIViewController you can place it on viewDidAppear, otherwise you can assume everything is already loaded and simply call it anywhere.

Gustavo Vollbrecht
  • 3,188
  • 2
  • 19
  • 37
  • Do I need to call something after saying .becomeFirstResponder? I initilized it with nameInput.isHidden = false nameInput.becomeFirstResponder() lbNames[0] = nameInput.text! and the textfield is simply let nameInput: UITextField = UITextField() do I need to do something else? – JustSomeoneWhoCodes Feb 18 '20 at 17:02
1

Call the following in the viewDidLoad of scoreboard, or whatever the entry point of that view is.

yourTextField.becomeFirstResponder()
emrepun
  • 2,496
  • 2
  • 15
  • 33