我是使用swift / Parse 的新手,并且无法更新_User中的用户列。问题是 Parse 已在运行getObjectinBackgroundWithId
,saveInBackground
未运行(无成功或错误)。如果我在没有按用户ID检索用户的情况下运行saveInBackgroundWithBlock
,我就没有问题了。
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var current = PFUser.currentUser().objectId
var userId = self.dictionary[indexPath.row]["userId"]
var query = PFQuery(className: "_User")
var user: PFObject?
self.query.getObjectInBackgroundWithId(userId) {
(success: PFObject!, error: NSError!) -> Void in
if success != nil {
success.addUniqueObject(current, forKey: "friendRequest")
user = success
}
}
var cell = tableView.cellForRowAtIndexPath(indexPath)
if cell?.accessoryType == UITableViewCellAccessoryType.Checkmark {
cell?.accessoryType = UITableViewCellAccessoryType.None
}
else {
self.searchController.active = false
let alertController = UIAlertController(title: "Alert", message: "Are you sure you want to add \(cell!.textLabel!.text!) to your friends?", preferredStyle: .Alert)
let OKAction = UIAlertAction(title: "Yes", style: .Default) { (action) in
user!.saveInBackgroundWithBlock {
(success: Bool!, error: NSError!) -> Void in
if success == true {
println("worked")
}
else {
println(error)
}
}
}
alertController.addAction(OKAction)
let cancelAction = UIAlertAction(title: "No", style: .Cancel) { (action) in
}
alertController.addAction(cancelAction)
self.presentViewController(alertController, animated: true) {
}
}
}
任何帮助将不胜感激!感谢