swift - 在 swift 中使用 parse 重置密码

标签 swift parse-platform uialertcontroller

好吧,那么我如何才能访问添加它的 block 末尾的“textField”呢?我尝试创建一个名为“alertTextField”的全局属性,然后将其设置为 block 中的 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)

}

最佳答案

查看此处的示例代码以了解详细信息:http://nshipster.com/uialertcontroller/

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

}

关于swift - 在 swift 中使用 parse 重置密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33048438/

相关文章:

swift - 包含值的 Firebase 查询

ios - '初始化(contentsOfURL :)' is unavailable: APIs deprecated as of iOS 7 and earlier are unavailable in Swift

swift - 在设备上运行时无法连接到 Realm 对象服务器

ios - 为什么我收到错误 : fatal error: unexpectedly found nil while unwrapping an Optional value?

swift - 如何从 UIAlertcontroller 获取文本输入或如何使用 Swift 等待输入

ios - UIAlertController - 默认覆盖 ActionSheet?

arrays - 需要帮助在 Swift 2 中的 API 调用中访问第二层数据

ios - 获取 PARSE objectIds 数组而不检索 PFObjects 本身

ios - 解析查询在 Swift 2.0 中不起作用

swift - 为什么不 becomeFirstResponder 在警报消息文本字段上触发软键盘