Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在swift中使用解析重置密码_Swift_Parse Platform_Uialertcontroller - Fatal编程技术网

在swift中使用解析重置密码

在swift中使用解析重置密码,swift,parse-platform,uialertcontroller,Swift,Parse Platform,Uialertcontroller,好的,那么我怎样才能访问添加块末尾的“textField”呢?我尝试创建一个名为“alertTextField”的全局属性,然后将其设置为块中的textField,以便我可以在其他操作中访问它,但它似乎不起作用。有什么建议吗 谢谢大家! @IBAction func resendPassword(sender: AnyObject) { let alertController : UIAlertController = UIAlertController(title: "Forgo

好的,那么我怎样才能访问添加块末尾的“textField”呢?我尝试创建一个名为“alertTextField”的全局属性,然后将其设置为块中的textField,以便我可以在其他操作中访问它,但它似乎不起作用。有什么建议吗

谢谢大家!

  @IBAction func resendPassword(sender: AnyObject) {

    let alertController : UIAlertController = UIAlertController(title: "Forgot Password?", message: "Enter your email", preferredStyle: UIAlertControllerStyle.Alert)

    let cancelAction: UIAlertAction = UIAlertAction(title: "Cancel", style: .Cancel) { action -> Void in

    }

    alertController.addAction(cancelAction)

    alertController.addTextFieldWithConfigurationHandler { (textField) -> Void in

        textField == self.alertTextField

        textField.delegate = self
        textField.placeholder = "Email"
    }

    let sendAction: UIAlertAction = UIAlertAction(title: "Send", style: UIAlertActionStyle.Default) { action -> Void in

        if (self.alertTextField?.text != nil) {

        PFUser.requestPasswordResetForEmailInBackground(self.alertTextField!.text)

        }

    }

    alertController.addAction(sendAction)

    self.presentViewController(alertController, animated: true, completion: nil)

}

有关详细信息,请查看此处的示例代码:


@如何接受答案
@IBAction func resendPassword(sender: AnyObject) {

    let alertController : UIAlertController = UIAlertController(title: "Forgot Password?", message: "Enter your email", preferredStyle: UIAlertControllerStyle.Alert)

    alertController.addTextFieldWithConfigurationHandler { (textField) -> Void in
        textField.placeholder = "Email"
    }

    let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)

    alertController.addAction(cancelAction)

    let sendAction = UIAlertAction(title: "Send", style: UIAlertActionStyle.Default) { _ in
        // below is how you access the textField
        let emailTextField = alertController.textFields![0] as UITextField
        if let email = emailTextField.text {
            PFUser.requestPasswordResetForEmailInBackground(email)
        }
    }

    alertController.addAction(sendAction)

    self.presentViewController(alertController, animated: true, completion: nil)

}