0

Basically, the question says it all. I thought about an alert but i need to actually have a text box inside and be able to save the text to a label. Any ideas on what I should use in this? I don't want to create a new view controller into a navigation. I just simply want a pop up view to open and close as needed.

All suggestions are greatly appreciated. Thanks!

AdrianGutierrez
  • 679
  • 1
  • 5
  • 11

1 Answers1

0

You can add a textfield in your alertController.

Please refer to this answer https://stackoverflow.com/a/33000328/1754559

let alertController = UIAlertController(title: "Your alert", message: "", preferredStyle: .alert)

let saveAction = UIAlertAction(title: "Save", style: .default, handler: {
    alert -> Void in

    guard let textField = alertController.textFields?[0] as UITextField else { return }
    yourLabel.text = textField.text
})

let cancelAction = UIAlertAction(title: "Cancel", style: .default, handler: {
    (action : UIAlertAction!) -> Void in })

alertController.addTextField { (textField : UITextField!) -> Void in
    textField.placeholder = "Whatever"
    //Other textField configurations
}

alertController.addAction(saveAction)
alertController.addAction(cancelAction)

present(alertController, animated: true, completion: nil)
Community
  • 1
  • 1
Giuseppe Lanza
  • 3,519
  • 1
  • 18
  • 40