我正在嘗試更新名爲「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