2016-03-28 15 views
0

補完ブロックに2番目のテキストフィールドを追加する際に問題があります。 誰かがもう1つのテキストフィールドを追加する方法を教えてください。 私はself.newFirstNameInput =を追加しようとしています。//これは私が理解していない部分ですか?UIAlert Swift 2に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 
    } 

私はあなたが

...私の答えの助けを願っています
関連する問題