我似乎无法在 SWIFT 中使用 UIAlertViewController 从 UITextField 获取输入值?

I cant seem to get the input value from UITextField using UIAlertViewController in SWIFT?

使用 iOS9 和 Swift 来测试这个 UIAlertViewController。到目前为止,我能够获得用户输入文本的弹出窗口("Email address")。事实上,我也有用户输入的文本。但文本显示:可选("test@test.com")。我提前道歉,但我现在是菜鸟。提前非常感谢您的提示。

@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)")
        }

    }))


}

通过添加 ! 作为其可选代码来更改操作中的代码:

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