I have this code, but I dont know how to show a textfield inside the UIAlertView.
var altMessage = UIAlertController(title: \"Warning\", message: \"This is A
Updated for swift 3 :
used below simple code:
func showAlertWithTwoTextFields() {
let alertController = UIAlertController(title: "Add Event", message: "Enter event and it's description", preferredStyle: .alert)
let saveAction = UIAlertAction(title: "Save", style: .default, handler: {
alert -> Void in
let eventNameTextField = alertController.textFields![0] as UITextField
let descriptionTextField = alertController.textFields![1] as UITextField
print("firstName \(String(describing: eventNameTextField.text)), secondName \(String(describing: descriptionTextField.text))")
if eventNameTextField.text != "" || descriptionTextField.text != ""{
}else{
// self.showAlertMessageToUser(title: "Alert", messageToUser: "Fields should not be empty, Please enter given info...")
// Show Alert Message to User As per you want
}
})
let cancelAction = UIAlertAction(title: "Cancel", style: .default, handler: {
(action : UIAlertAction!) -> Void in
})
alertController.addTextField { (textField : UITextField!) -> Void in
textField.placeholder = "Enter event Name"
}
alertController.addTextField { (textField : UITextField!) -> Void in
textField.placeholder = "Enter event description in short"
}
alertController.addAction(saveAction)
alertController.addAction(cancelAction)
self.present(alertController, animated: true, completion: nil)
}
// Enjoy Coding...!