In Swift Playgrounds for iPad, how do you request keyboard input when a user presses a UIButton, then pass the input to a variable or container?
Asked
Active
Viewed 135 times
1 Answers
1
You most likely want to use a UITextField. Just by placing the text field on your storyboard, the user can click it and enter what they want. You can then pass what they entered into a variable by entering var textEntered = textField.text
. If you really wanted to, you could also focus the textField when a button is tapped by putting textField.becomeFirstResponder()
in the button’s action. If you don’t want the text field to be shown, you can put textField.isHidden = true
in viewDidLoad. Hope this helps!
-
Just to clarify, this is a playground, so First Responder and viewDidLoad don't apply. – Colin FB Mar 16 '19 at 04:10