ios - Parse.com 的一些列未在 segue 上更新

标签 ios iphone swift parse-platform

我正在尝试更新一些有关解析的列。在这里,只有 gotpromoCode 在 segue 之前更新。但是,如果我从下一个 View Controller 返回,同一按钮上的单击函数将再次被调用,并且其他列 promoCode 和 senderUserId 会被更新。我已经设置了断点,并看到更新列的代码在这两列的 segue 之前被调用,但第一次它们仍然没有更新。

 var promoCode = ""

//if promocode is nil
if ((self.currentUser["promoCode"]) == nil)
{
    let nameString = self.firstname.text!+self.lastname.text!

    PFCloud.callFunctionInBackground("createPromoCode", withParameters: ["nameString" : nameString]){ response, error in
        if let error = error {

            print (error)
        }
        else {

            print("Invite sent")

            print("the invitation code is: \(String(response!))")

            promoCode = String(response!)

            PFUser.currentUser()!.setValue(promoCode, forKey: "promoCode")
        }
    }

}

//validating promo code
if ( self.promocodeText.text?.isEmpty == false )// && PFUser.currentUser()!["gotpromoCode"] == nil )
{

    var query1 = PFQuery(className:"_User")
    query1.whereKey("promoCode", equalTo:self.promocodeText.text!)
    query1.findObjectsInBackgroundWithBlock {
        (objects: [PFObject]?, error: NSError?) -> Void in

        if error == nil {

            PFUser.currentUser()!.setValue(self.promocodeText.text, forKey: "gotpromoCode")
            // The find succeeded.
            print("Successfully retrieved \(objects!.count) scores.")

            // Do something with the found objects
            if let objects = objects {
                for object in objects {
                    print(object.objectId)

                    // self.senderUserId = object.objectId!
                    PFUser.currentUser()!.setValue(object.objectId!, forKey: "senderUserId")
                    print("senderUserId is: \(object.objectId!)")

                }
            }


        } else {
            // Log details of the failure
            print("Error: \(error!) \(error!.userInfo)")
            self.displayAlert("Error!", body: "Promo Code does not exists")

        }

    }

}


PFUser.currentUser()!.saveInBackgroundWithBlock {
    (success: Bool, error: NSError?) -> Void in
    if (success) {
        self.performSegueWithIdentifier(self.goToAccount, sender: self)

    } else {
        // There was a problem, check error.description
    }
}

我已经检查了断点中的值,但不知道为什么会发生这种情况。

最佳答案

我通过设置值后保存结果来解决这个问题。

  PFUser.currentUser()!.saveInBackground()

所以我用这个就像

PFUser.currentUser()!.setValue(object.objectId!, forKey: "senderUserId")
 PFUser.currentUser()!.saveInBackground()

与 promoCode 类似,然后它就起作用了。

关于ios - Parse.com 的一些列未在 segue 上更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34115846/

相关文章:

ios - 当应用程序进入后台时,Swift UILabel 为 nil(错误)

iphone - 下载 *.tgz 文件并将其解压到 Documents 目录的子目录中

javascript - Android 或 ios 平台上的 Node -WebKit 应用程序

ios - iPhone 模拟器 10.0 - 语音识别不可用

ios - 体系结构 x86_64 的 undefined symbol &&找不到体系结构 x86_64 的符号

IOS:从 uitableviewcell 验证用户发送重定向到相应的 Controller ?

ios - 调整 UIView 的大小,以便我绘制的内容可见 - Objective C

ios - QuickBlox : didReceiveNewSession Method is not gettimg called in swift

ios - UIAlert Controller 上的图标

ios - 获取具有 alpha 值的纯色版本,同时考虑下面的颜色