Parse.com有些专栏未在segue上更新

时间:2015-12-06 09:20:16

标签: ios iphone swift parse-platform

我正在尝试更新解析的几个列。这里,只有gotpromoCode在segue之前得到更新。但是如果我从下一个视图控制器返回,则在同一个按钮上再次调用click函数,并更新其他列promoCode and 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
    }
}

我已经检查了断点中的值,并且没有想到为什么会发生这种情况。

1 个答案:

答案 0 :(得分:0)

我在设置值后保存结果解决了这个问题。

  PFUser.currentUser()!.saveInBackground()

所以我用它就像

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

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