You may go with UIAlertController instead of UIAlertView.
I've already implemented and tested too using UIAlertController for what you actually want. Please try the following code
var tField: UITextField!
func configurationTextField(textField: UITextField!)
{
print("generating the TextField")
textField.placeholder = "Enter an item"
tField = textField
}
func handleCancel(alertView: UIAlertAction!)
{
print("Cancelled !!")
}
var alert = UIAlertController(title: "Enter Input", message: "", preferredStyle: .Alert)
alert.addTextFieldWithConfigurationHandler(configurationTextField)
alert.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler:handleCancel))
alert.addAction(UIAlertAction(title: "Done", style: .Default, handler:{ (UIAlertAction) in
print("Done !!")
print("Item : (self.tField.text)")
}))
self.presentViewController(alert, animated: true, completion: {
print("completion block")
})
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…