title: Access indexPath.row in button function Swift
body: <p>I am trying to remove selected row with button. Therefore I need indexPath.row, I write value to global variable, but when I access it in button, it returns nil to me. </p>
  
  <pre><code>var selectedRow = ""
  
  func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
      let selectedEvent = myConversationRows[indexPath.row]
      selectedRow = selectedEvent.id!
  }
  
  @IBAction func cancelConversation(_ sender: Any) {
  
      print("selected")
      print(self.selectedRow)
  }
  </code></pre>
  
  <p>I guess that when I tap on button didSelectRowAt is not triggered. I have tried different methods, but none of them work.</p>
  
  <p><a href="https://i.stack.imgur.com/nebCa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nebCa.png" alt=""></a></p>