2015-10-18 47 views
0

使用iOS9和Swift來測試這個UIAlertViewController。到目前爲止,我能夠獲得用戶輸入文本的彈出框(「電子郵件地址」)。實際上,我也有用戶輸入的文字。但文本顯示:可選(「[email protected]」)。我提前道歉,但我現在是新手。提前非常感謝您的提示。我似乎無法使用SWIFT中的UIAlertViewController從UITextField獲得輸入值?

@IBAction func UserForgotPasswordAction(sender: AnyObject) { 

func handleCancel(alertView: UIAlertAction!) 
    { 
     print("Cancelled !!") 
    } 

    let alert = UIAlertController(title: "Enter your Email Address", message: "", preferredStyle: UIAlertControllerStyle.Alert) 
    UIAlertViewStyle.PlainTextInput 
    alert.addTextFieldWithConfigurationHandler({(textField: UITextField) in 
     print("generating the TextField") 
     textField.placeholder = "Email address" 
     textField.textAlignment = NSTextAlignment.Center 

     print("THE Input 01: \(textField.text)") 
    }) 
    self.presentViewController(alert, animated: true, completion: { 
     print("completion block") 
    }) 

    alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler:handleCancel)) 

    alert.addAction(UIAlertAction(title: "Reset", style: UIAlertActionStyle.Default, handler:{ (UIAlertAction)in 

     if let textField2 = alert.textFields!.first { 
      print("THE Input: \(textField2.text)") 
      PFUser.requestPasswordResetForEmailInBackground("\(textField2.text)") 
     } 

    })) 


} 

回答

0

更改內部動作的代碼加入!作爲其可選:

if let textField2 = alert.textFields!.first { 
     print("THE Input: \(textField2.text!)") 
     PFUser.requestPasswordResetForEmailInBackground("\(textField2.text!)") 
    } 
+0

完美!非常感謝!! – Jignesh