0

I was wondering if it was possible to have an alert with preloaded text in it. For example, if my app guessed something I would want the guess to appear in the alert text box but the user could delete the text and change the answer if they wanted to.

Thank you

4 Answers4

0

yes you can. You can create a custom alertView from a xib and you can input there an UITextField ,so the user can have the opportunity to change the text

Enea Dume
  • 3,014
  • 3
  • 21
  • 36
0

Simply Create an alert controller leave the title and message empty and add a TextField to your alert that way you can preload your text to the TextField and user can also edit the text

Khalid Afridi
  • 913
  • 5
  • 12
0

Have you had a look at this page : How to add a TextField to UIAlertView in Swift ?

You could put textfields (or anything else you'd like) inside the alertview and so that the user could interact with it more deeply :)

Vincent

Vincent Monteil
  • 568
  • 5
  • 22
0

Just add text field in alert controller.

let alertController = UIAlertController(title: "title", message: "please enter words", preferredStyle: UIAlertControllerStyle.Alert)

alertController.addTextFieldWithConfigurationHandler { (txtUsername) -> Void in
     usernameTextField?.text = "preload"
     usernameTextField?.placeholder = "placeholder"

 }

self.presentViewController(alertController, animated: true, completion: nil)
Lumialxk
  • 6,239
  • 6
  • 24
  • 47