2016-03-28 3 views
0

У меня возникли проблемы с добавлением второго текстового поля в мой блок завершения. Может кто-нибудь, пожалуйста, покажите мне, как добавить еще одно текстовое поле. Я пытаюсь добавить self.newFirstNameInput = // это часть, которую я не понимаю?Добавить второе текстовое поле в UIAlert Swift 2

func insertNewObject(sender: AnyObject) { 
    let newNameAlert = UIAlertController(title: "Add New User", message: "What's the user's name?", preferredStyle: UIAlertControllerStyle.Alert) 
    newNameAlert.addTextFieldWithConfigurationHandler { (alertTextField) -> Void in 
    self.newLastNameInput = alertTextField 
} 

newNameAlert.view.setNeedsLayout() 

newNameAlert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Default, handler: nil)) 
newNameAlert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: addNewUser)) 
presentViewController(newNameAlert, animated: true, completion: nil) 
} 

ответ

0
var txtField1: UITextField! 
    var txtField2: UITextField! 

    override func viewDidLoad() 
    { 
     let alert = UIAlertController(title: "Enter Input", message: "", preferredStyle: UIAlertControllerStyle.Alert) 

     alert.addTextFieldWithConfigurationHandler(addTextField1) 
     alert.addTextFieldWithConfigurationHandler(addTextField2) 

     alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: { (UIAlertAction)in 
      print("Cancel") 
     })) 
     alert.addAction(UIAlertAction(title: "Done", style: UIAlertActionStyle.Default, handler:{ (UIAlertAction)in 
      print("Done") 
      print("First Name : \(self.txtField1.text!)") 
      print("Last Name : \(self.txtField2.text!)") 
     })) 
     self.presentViewController(alert, animated: true, completion: nil) 
    } 

    func addTextField1(textField: UITextField!) 
    { 
     textField.placeholder = "Enter first name" 
     txtField1 = textField 
    } 

    func addTextField2(textField: UITextField!) 
    { 
     textField.placeholder = "Enter last name" 
     txtField2 = textField 
    } 

я надеюсь, что мой ответ поможет ...

Смежные вопросы