title: Select and Unselect custom button in tableViewCell swift ios
body: <p>Custom button in tableViewCell and there is list of item which I want to handle through this button.When click on first button first cell is selecting and when click on second button in tableView cell second cell is selecting but not deselecting first one.Please check my code.</p>
  <p>TableViewCell:</p>
  <pre><code>  var selectCategory: ((Int) -&gt; Void)?
     
  
      @IBAction func didTapSelected(_ sender: UIButton) {
          selectCategory?(sender.tag)
      }
  </code></pre>
  <p>CellForRowAt method:</p>
  <pre><code>cell.buttonRadio.tag = indexPath.row
  cell.selectCategory = { num in
       if !self.selectedRows.contains(num) {
                          self.selectedRows.append(num)
                              cell.buttonRadio.setImage(UIImage(named: &quot;radioSelected&quot;), for: .normal)
                              self.buttonLink.isUserInteractionEnabled = true
                              self.buttonLink.backgroundColor = UIColor.init(hex: &quot;#453073&quot;)
                          for visited in self.selectedRows {
                              if num == visited {
                                  cell.buttonRadio.setImage(UIImage(named: &quot;radioSelected&quot;), for: .normal)
                                  self.buttonLink.isUserInteractionEnabled = true
                                  self.buttonLink.backgroundColor = UIColor.init(hex: &quot;#453073&quot;)
                              }
                               if num != visited {
                                  cell.buttonRadio.setImage(UIImage(named: &quot;radioUnselected&quot;), for: .normal)
                                  self.buttonLink.isUserInteractionEnabled = false
                                  self.buttonLink.backgroundColor = UIColor.init(hex: &quot;#A297B9&quot;)
                                  self.selectedRows.remove(at: self.selectedRows.firstIndex(of: visited)!)
                              }
                          }
                      }
  </code></pre>