I need to get the text from the text fields in my alert view when the Input button is pressed.
func inputMsg() {
var points = \"\"
var outOf = \"\"
The UIAlertController has a textFields
property. That's its text fields. Any of your handlers can examine it and thus can get the text from any of the text fields.
As requested here is an implementation solution.
alertController.addAction(UIAlertAction(title: "Submit", style: UIAlertActionStyle.Default,handler: {
(alert: UIAlertAction!) in
if let textField = alertController.textFields?.first as? UITextField{
println(textField.text)
}
}))
As stated above, the alertController has a property called textFields
. You can conditionally unwrap that property to safely access a text field if you have added one. In this case since there is only one text field I just did the unwrap using the first
property. Hope it helps.