title: UIButton in UITableViewCell is being reused
body: <p>My tableview displays podcast data. All cells are reused fine and display podcasts in the right order. I add download and play buttons as subviews of each cell. When I scroll down the list, the play button which is meant to be hidden for non-downloaded episodes will be shown and will hold the data of the cell which previously initiated a download. For example if I tap download button in cell 1, it will download the right episode and the play button will play the episode perfectly. If I scroll down to cell 10, the same play button will appear and will play episode from button 1. What's wrong with my code?</p>
  
  <pre><code>override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -&gt; PFTableViewCell? {
      let cell: PFTableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! PFTableViewCell
      if let title = object?["title"] as? String {
          cell.textLabel?.text = title
          let downloadButton = UIButton(type: UIButtonType.Custom)
          downloadButton.frame = CGRectMake(cell.contentView.bounds.width - 100, cell.contentView.bounds.height / 2, 100, 35)
          downloadButton.setTitle("Download", forState: .Normal)
          downloadButton.setTitleColor(UIColor.blueColor(), forState: .Normal)
          downloadButton.tag = indexPath.row
          downloadButton.addTarget(self, action: "downloadEpisode:", forControlEvents: .TouchUpInside)
          cell.addSubview(downloadButton)
          let playButton = UIButton(type: UIButtonType.Custom)
          playButton.frame = CGRectMake(cell.contentView.bounds.width - 100, cell.contentView.bounds.height - 89, 100, 35)
          playButton.setTitle("Play", forState: .Normal)
          playButton.setTitleColor(UIColor.blueColor(), forState: .Normal)
          playButton.tag = indexPath.row
          playButton.addTarget(self, action: "playEpisode:", forControlEvents: .TouchUpInside)
          if let isDownloaded = object?["isDownloaded"] as? String {
              if isDownloaded == "yes" {
                  playButton.hidden = false
              } else {
                  playButton.hidden = true
              }
          }
          cell.addSubview(playButton)
      }
      return cell
  }
  </code></pre>
  
  <p>Edit: </p>
  
  <p>I've also tried this but it doesn't work and still creates 1 more button per cell:</p>
  
  <pre><code>     override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -&gt; PFTableViewCell? {
      let cell: PFTableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! PFTableViewCell
      if let title = object?["title"] as? String {
          cell.textLabel?.text = title
      }
          if let button = cell.viewWithTag(indexPath.row) {
              print(button)
          } else {
              if let isDownloaded = object?["isDownloaded"] as? String {
                  if isDownloaded == "yes" {
                      let downloadButton = UIButton(type: UIButtonType.Custom)
                      downloadButton.frame = CGRectMake(cell.contentView.bounds.width - 100, cell.contentView.bounds.height / 2, 100, 35)
                      downloadButton.setTitle("Play", forState: .Normal)
                      downloadButton.setTitleColor(UIColor.blueColor(), forState: .Normal)
                      downloadButton.tag = indexPath.row
                      downloadButton.addTarget(self, action: "playEpisode:", forControlEvents: .TouchUpInside)
                      cell.addSubview(downloadButton)
                  } else {
                      let downloadButton = UIButton(type: UIButtonType.Custom)
                      downloadButton.frame = CGRectMake(cell.contentView.bounds.width - 100, cell.contentView.bounds.height / 2, 100, 35)
                      downloadButton.setTitle("Download", forState: .Normal)
                      downloadButton.setTitleColor(UIColor.blueColor(), forState: .Normal)
                      downloadButton.tag = indexPath.row
                      downloadButton.addTarget(self, action: "downloadEpisode:", forControlEvents: .TouchUpInside)
                      cell.addSubview(downloadButton)
                  }
              }
      }
  
      return cell
  }
  </code></pre>
  
  <p>Edit2:</p>
  
  <p>Added download method:</p>
  
  <pre><code>        func downloadEpisode(sender: UIButton) {
      print("Downloading..")
      let indexPath = NSIndexPath(forRow: sender.tag, inSection: 0)
  
      let object = self.objectAtIndexPath(indexPath)
      if let result = object {
      let urlstring = result["downloadURL"] as? String
      if urlstring != nil {
      let episodeURL = NSURL(string: urlstring!)
          downloader.downloadPodcastEpisode(episodeURL!, podcast: result)
          }
      }
  }
  </code></pre>
  
  <p>Answer:</p>
  
  <p>Although all answers were right, I have decided to remove the button download/play on cell taps in the end. Many thanks!</p>