我正在尝试更新名为“currentUploaded”的Parse.com表中的一个值。更新Parse.com中的值
这是Parse.com代码我查询: http://pastebin.com/Jr0EcJuy
Parse.com“currentUploads”类:http://i.stack.imgur.com/E8tND.png
这是按钮我想要做的更新值(因为它是现在,它在另一个类中创建一个新的行,但我只是想增加“reportedCount”选择的项目,而不是:
@IBAction func reportContentAction(sender: AnyObject) {
let buttonPosition = sender.convertPoint(CGPointZero, toView: self.collectionView)
let indexPath = self.collectionView.indexPathForItemAtPoint(buttonPosition)
////
println(indexPath?.item)
////
let post = self.arrayOfDetails[indexPath!.item]
var alertMessage = NSString(format:"*User: %@\r *Text: %@\r *Created at %@", post.username, post.text, post.CreatedAt)
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")
var currentUploads = PFObject(className: "banned")
currentUploads["username"] = post.username
currentUploads["imageText"] = post.text
currentUploads["imageFile"] = post.image
currentUploads["identifierForVendor"] = post.deviceID
currentUploads["flaggedBy"] = PFUser.currentUser()?.username
currentUploads["flaggedByUUID"] = UIDevice.currentDevice().identifierForVendor.UUIDString
currentUploads.saveInBackgroundWithBlock({ (success: Bool, error: NSError?) -> Void in
if error == nil{
//**Success saving, now save image.**//
currentUploads.saveInBackgroundWithBlock({ (success: Bool, error: NSError?) -> Void in
if error == nil{
// Take user home
print("Data uploaded")
// Show UIAlertView
let alert = UIAlertView()
alert.title = "Message"
alert.message = "You report has been sent. Thank you for your support."
alert.addButtonWithTitle("Close")
alert.show()
}
else{
print(error)
}
})
}
else{
print(error)
}
})
}))
reportAlert.addAction(UIAlertAction(title: "Cancel", style: .Default, handler: { (action: UIAlertAction!) in
println("Handle Cancel Logic here")
}))
presentViewController(reportAlert, animated: true, completion: nil)
}
我自己也尝试使用此代码,当用户点击弹出的是,但它不起作用:
reportAlert.addAction(UIAlertAction(title: "Yes", style: .Default, handler: { (action: UIAlertAction!) in
println("Handle Report Logic here")
var query = PFQuery(className: "currentUploads")
query.whereKey("imageFile", equalTo: post.image)
query.getFirstObjectInBackgroundWithBlock {
(myObject: PFObject?, error: NSError?) -> Void in
if (error != nil){
println(error)
//
}
else{
query.setValue("1", forKey: "reportedCount")
}
}
}))
请问,有人可以告诉我它应该是正确的吗?一直在努力对这个对于很多很多时间现在..
我不知道我会怎么做不同的课堂?你的意思是继承或什么?我不知道如何从我的方法做到这一点。 – IdaEmilie
我不明白一些class.objectid,要放在那里? – IdaEmilie
你想改变表中的某一行(对象)。这一行有objectId。使用这个objectId是告诉表什么对象你想改变的最简单的方法。 – lithium