-4

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?

Colin FB
  • 110
  • 1
  • 7

1 Answers1

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!