我正在尝试更新 Parse 中“currentUploads”类中的列: Image here
这就是我正在尝试的
@IBAction func reportButtonAction(sender: AnyObject) {
println("Report Button Pressed")
let buttonPosition = sender.convertPoint(CGPointZero, toView: self.collectionView)
let indexPath = self.collectionView.indexPathForItemAtPoint(buttonPosition)
var alertMessage = NSString(format: "*User: %@\r *Text: %@\r *Created at %@", imageUploader[indexPath!.row], imageText[indexPath!.row]/*, imageCreated[indexPath!.row]*/)
var reportAlert = UIAlertController(title: "Report Content", message:alertMessage as String, preferredStyle: UIAlertControllerStyle.Alert)
reportAlert.addAction(UIAlertAction(title: "Yes", style: .Default, handler: { (action: UIAlertAction!) in
println("Handle Report Logic here")
self.reportContent()
}))
reportAlert.addAction(UIAlertAction(title: "Cancel", style: .Default, handler: { (action: UIAlertAction!) in
println("Handle Cancel Logic here")
}))
presentViewController(reportAlert, animated: true, completion: nil)
}
func reportContent(){
let someQuery = PFQuery(className: "currentUploads")
someQuery.getObjectInBackgroundWithId("imageFile") {
(updatedObject: PFObject?, error: NSError?) -> Void in
if error != nil {
print(error)
} else if let updatedObject = updatedObject {
updatedObject["reportedCount"] = "1"
updatedObject.saveInBackground()
}
}
}
因此,我想将 func reportContent
中所选图像的“reportedCount”更新/增加到 1,但出现此错误:
[Error]: No results matched the query. (Code: 101, Version: 1.8.0) Optional(Error Domain=Parse Code=101 "No results matched the query." UserInfo=0x7fae8a484aa0 {error=No results matched the query., NSLocalizedDescription=No results matched the query., code=101})
最佳答案
我相信这是因为您查询了其中包含“imageFile”的所有实例,而不是实际的行。你想使用类似
someQuery.whereKey(objectId, EqualTo: objectId)
并使用
someQuery.findObjectsInBackgroundWithBlock
其中objectId 是您要更改reportedCount 的对象的对象ID。
那么你可以这样做
object.setValue(object["reportedCount"] as! Int + 1, forKey: "reportedCount")
这都是伪代码,但这是我在用户添加新 friend 时增加 friend 数量的方法。
关于xcode - 更新 Parse 类中列中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33192914/