title: Swift 3: How to use action button in multiple sections of a table view?
body: <p>I'm trying to run a unique function when a button is clicked in each row of each section. 
  The problem for example is, if i have 3 rows in 3 sections and i configure the first row to run a function when the button is pressed, the first row for all 3 sections runs the same function. I'm trying to achieve running unique functions for all rows in different sections. </p>
  
  <p>This is my <code>tableView</code> code:</p>
  
  <pre><code>func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
      let cell = tableView.dequeueReusableCell(withIdentifier: languageID, for: indexPath) as! LanguageTableViewCell
  
      switch indexPath.row {
      case 0:
          cell.phraseLBL.text = "description 1"
          cell.playBtn.tag = indexPath.row
          cell.playBtn.addTarget(self, action: #selector(PhraseVC.pressPlay), for: .touchUpInside)
  
      case 1:
          cell.phraseLBL.text = "description 2"
          cell.playBtn.tag = indexPath.row
          cell.playBtn.addTarget(self, action: #selector(PhraseVC.pressPlay), for: .touchUpInside)
  
      case 2:
          cell.phraseLBL.text = "description 3"
          cell.playBtn.tag = indexPath.row
          cell.playBtn.addTarget(self, action: #selector(PhraseVC.pressPlay), for: .touchUpInside)
      default:
          break
      }
  
      return cell
  }
  </code></pre>
  
  <p>And this is the <code>IBAction</code> of <code>Button</code>:</p>
  
  <pre><code>@IBAction func pressPlay(sender: UIButton){
  
          switch sender.tag {
          case 0:
              print("button 1 pressed")
  
          case 1:
              print("button 2 pressed")
  
          case 2:
              print("button 3 pressed")
  
          case 3:
              print("button 4 pressed")
  
          case 4:
              print("button 5 pressed")
          default:
              break;
          }
      }
  </code></pre>