ios - Vote implementation in parse -


i stuck long time. trying implement vote feature in collection view. if user taps button adds 1 vote parse , shows on label. code when parse dashboard see new row create , number of votes not going post enter image description here

my code cell

import uikit import parseui import parse  var votes = [pfobject]()   class newcollectionviewcell: uicollectionviewcell {     var parseobject = pfobject(classname: "posts")     @iboutlet weak var postsimageview: pfimageview!     @iboutlet weak var postslabel: uilabel!     @iboutlet weak var voteslabel:uilabel?      override func awakefromnib() {         super.awakefromnib()         // initialization code         postslabel.textalignment = nstextalignment.center          print("passing11")      }       @ibaction func vote(sender: anyobject) {                  if let votes = parseobject.objectforkey("votes") as? int {                     parseobject.setobject(votes + 1, forkey: "votes")                     parseobject.saveinbackgroundwithtarget(nil, selector: nil)                     voteslabel?.text = "\(votes + 1) votes"                     print("passing22")                 }                 else                 {                     parseobject.setobject(1, forkey: "votes")                     parseobject.saveinbackgroundwithtarget(nil, selector: nil)                     voteslabel?.text = "1 votes"                      print("passing33")                 }             }} 

and collection view

        if let votes = parseobject.objectforkey("votes") as? int {             cell.voteslabel?.text = "\(votes) votes"         }         else         {             cell.voteslabel?.text = "0 votes"         }     return cell      } 

how can make work? thank you.

from remember in parse project. if need retrieve , update existing row in parse need create pfquery object first , retrieve desired row using query object. , can update "vote" or whatever attribute value want to. kindly try that.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -