title: Voting buttons with Parse in Swift
body: <p><strong>A quick overview of what I'm trying to make.</strong> I'm making an app to show my film reviews. I have a <code>PFQueryTableviewController</code> of which I use a custom cell. This table shows films which come from my Parse database. In each cell, there a 3 UIButtons, of which I want the user to use to vote for the film (happyVote, OkVote, sadVote). Over the top of each button is a UILabel that simply displays a count. </p>
  
  <p><strong>How I want it to work</strong></p>
  
  <ol>
  <li>When a user presses one of the buttons, the vote increases by 1.</li>
  <li>When a user presses the same button again, the vote decreases by 1. Or,</li>
  <li>If the user had pressed a different button, the vote decreases on the first button and increases on the button just pressed.</li>
  <li>The user can only ever vote on one of the buttons. </li>
  <li>The vote is shown by the UILabel showing the count, and by the button image changing. </li>
  </ol>
  
  <p><strong>See below for a visual:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/WZsjV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WZsjV.png" alt="enter image description here"></a></p>
  
  <p>This is what I've added in Parse:</p>
  
  <p><a href="https://i.stack.imgur.com/TOS9c.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TOS9c.png" alt="enter image description here"></a></p>
  
  <p>So far, I've added the code to increase the vote count in Parse, in my <code>TableViewController.swift</code>:</p>
  
  <pre><code>@IBAction func upVoteButton(sender: AnyObject) {
  
      let hitPoint = sender.convertPoint(CGPointZero, toView: self.tableView)
      let hitIndex = self.tableView.indexPathForRowAtPoint(hitPoint)
  
      let object = objectAtIndexPath(hitIndex)
      object!.incrementKey("UpVoteCount")
      object!.saveInBackground()
      self.tableView.reloadData()
  
  }
  </code></pre>
  
  <p>This kind of works, except, the user can keep increasing the count, and they can vote on all 3 buttons. And it doesn't change the Button Image when pressed. </p>
  
  <p>In my <code>cellForRowAtIndexPath</code> method, I've put:</p>
  
  <pre><code> let downVote = object!.valueForKey("DownVoteCount") as! Int
      cell.downVoteLabel.text = "\(downVote)"
      let middleVote = object!.valueForKey("MiddleVoteCount") as! Int
      cell.middleVoteLabel.text = "\(middleVote)"
      let upVote = object!.valueForKey("UpVoteCount") as! Int
      cell.upVoteLabel.text = "\(upVote)"
  </code></pre>
  
  <p>I have searched for a while for some examples of how to figure the rest out, but can't find anything, and I'm really struggling to figure the next steps out. </p>
  
  <p>Any help will be greatly appreciated, and please let me know if you need/want to see anymore of my code. Thanks</p>