Get Text Input WITHOUT UITextField Swift

253 Views Asked by At

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

There are 2 best solutions below

4
emrepun On BEST ANSWER

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

yourTextField.becomeFirstResponder()
1
Gustavo Vollbrecht On

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.