быстры 2,0:
1) Создание общественной переменной
var alertController: UIAlertController?
2) Настройка оповещения Контроллер
alertController = UIAlertController(title: "Alert Title", message: "Alert Message", preferredStyle: .Alert)
//old password textfield
alertController!.addTextFieldWithConfigurationHandler({(textField: UITextField!) in
textField.placeholder = "Password"
textField.secureTextEntry = true
textField.addTarget(self, action: "alertTextFieldDidChange:", forControlEvents: .EditingChanged)
})
//new password textfield
alertController!.addTextFieldWithConfigurationHandler({(textField: UITextField) -> Void in
textField.tag = 1002
textField.placeholder = "New Password"
textField.secureTextEntry = true
textField.addTarget(self, action: "alertTextFieldDidChange:", forControlEvents: .EditingChanged)
})
//confirm password textfield
alertController!.addTextFieldWithConfigurationHandler({(textField: UITextField) -> Void in
textField.tag = 1003
textField.placeholder = "Confirm Password"
textField.addTarget(self, action: "alertTextFieldDidChange:", forControlEvents: .EditingChanged)
})
alertController!.addAction(UIAlertAction(title: "Submit", style: UIAlertActionStyle.Default, handler: { (action) -> Void in
//Do after submit is clicked
}))
alertController!.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Default, handler: { (action) -> Void in
self.alertController?.dismissViewControllerAnimated(true, completion: nil)
}))
self.presentViewController(alertController!, animated: true, completion: nil)
3) Принимая TextField значения
func alertTextFieldDidChange(sender: UITextField) {
alertController = self.presentedViewController as? UIAlertController
let firstTextField: UITextField = (alertController?.textFields![0])!
let secondTextField: UITextField = (alertController?.textFields![1])!
let thirdTextField: UITextField = (alertController?.textFields![2])!
print(firstTextField.text)
print(secondTextField.text)
print(thirdTextField.text)
}
Примечание:
Что вы планируете использовать? Вы должны посмотреть на UIAlertControlle: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIAlertController_class/ –
Возможный дубликат [Как добавить несколько UITextFields в UIAlertView в iOS 7?] (Http://stackoverflow.com/questions/19090547/how-to-add-multiple-uitextfields-to-a-uialertview-in-ios-7) –
Вы должны создать настраиваемое оповещение для добавления текстовых полей, просто создайте пользовательский класс UIView и сделайте это похоже на то, что вы хотите. Затем просто покажите его в своем классе, а не вызовите UIAlertView. –