ios - 快速解析检查用户输入的输入并刷新值

标签 ios swift input parse-platform refresh

我正在尝试检查用户输入的数据是否与类中的对象数据匹配。比较有效,但刷新则不然。

这是代码。

let query = PFQuery(className: "registeredCodes")
    query.whereKey("code", equalTo: userCodeEnter.text!)
    query.getFirstObjectInBackgroundWithBlock {
        (object: PFObject?, error: NSError?) -> Void in
        if error != nil || object == nil {
            print("The getFirstObject request failed.")
        } else {
            // The find succeeded.
            print("Successfully retrieved the object.")
            let totalPoints = PFUser.currentUser()?["points"] as? Int
            self.userPointsLabel.text =  "Punkte: " + "\(totalPoints)"


        }
            }

之后

let totalPoints = PFUser.currentUser()?["points"] as? Int
            self.userPointsLabel.text =  "Punkte: " + "\(totalPoints)"

它只是在原始数字前面添加一个“可选”,而不是新数字。它看起来像可选(5)

最佳答案

您的代码正在查询(从服务器提取对象,并进行一些检查)registeredCodes 类。然后,完成后,您的代码将使用 PFUser.currentUser 执行某些操作。这是一个不同的类(class)。该查询不会导致 PFUser.currentUser 更新。

如果 PFUser.currentUser 预计已更改,那么您需要对其调用 refreshInBackgroundWithBlock: 来获取这些更新,以便您可以使用它们(它们将在以下时间准备就绪):调用完成 block 。

关于ios - 快速解析检查用户输入的输入并刷新值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33875046/

相关文章:

ios - 重定向回主屏幕时,按钮不起作用且导航 Pane 不显示

ios - iOS 上的 webRTC : Can't send SDP answer, RTCPeerConnection.setRemoteDescription() 失败

css - 如何在鼠标悬停时设置 "submit"输入的样式,单击?

ios - 并不可怕的Segues

AngularJS 将值复制到另一个输入

html - 在右侧带有按钮的 div 中输入剩余可用空间的文本

ios - 在 iOS 设备上访问用户的 iTunes 资料库是否需要许可?

ios - 从 iOS7 中的应用程序中关闭所有 UIAlertview

swift - 什么是 Swift 中的工厂类方法?

ios - TableView 行意外重新排序