我正在尝试更新一些有关解析的列。在这里,只有 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/