2015-10-18 57 views
0

我想以更新類「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() 
     } 
    } 
} 

所以我想更新/遞增「reportedCount」 1在func reportContent選定的圖像,但我得到這個錯誤:

[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})

回答

0

我相信這是因爲你在它們中查詢所有具有「imageFile」的實例,而不是實際的行。你想使用類似

someQuery.whereKey(objectId, EqualTo: objectId) 

,並使用

someQuery.findObjectsInBackgroundWithBlock 

其中OBJECTID是,你想改變的reportedCount對象的對象ID。

那麼你可以做

object.setValue(object["reportedCount"] as! Int + 1, forKey: "reportedCount") 

這都是僞代碼,但它是我所做遞增的朋友,當他們增加了新的朋友我的用戶有多少。

+0

我做錯了什麼? - http://s30.postimg.org/rkjj17erl/Screen_Shot_2015_10_19_at_19_11_51.png – IdaEmilie

+0

試過這個,不知道爲什麼它不起作用:http://pastebin.com/hRwFSMaT – IdaEmilie