Q: play/Pause button image changes after Table view scrolling I added a button in a tableView cell through which the music URL can be played in AVPlayer. I can play the music but the problem is when I tap play it changes to pause and when I scroll it down and come back to top it changes to play again. it's not holding the state of the button. 
And also when I will tap the play button of any cell I want the other button of other cells should also go back to play icon so that no overlaps happen. 
Here's my code of the button action. I'm using a delegate in a cell's class to access this button IBAction. 
extension HomeViewController: RadiocellDelegate {
  func playButtonTapped(cell: RadioCell) {
    guard let indexpath =
      self.listRadioTavleView.indexpathForView(cell.playButton)
    else { return }

    cell.playButton.tag = indexpath.row

    // IF Play Button
    if cell.playButton.currentImage = UIImage(named: "play_icon") {
      loadRadio(radioURL: musicURL[indexpath.row])
      cell.playButton.setImage(UIImage(named: "pause_icon"), for: .normal)
    } else { // IF PAUSE BUTTON
      cell.playButton.setImage(UIImage(named: "play_icon"), for: .normal)
      player.pause()
      pause = true
    }
  }
}


A: You need not store current playing cell index. Take a global variable in class 'currentPlayingIndex'.
let currentPlayingIndex : Int?

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) 
-> UITableViewCell {
    //Your other code

    cell.tag = indexPath.row
    if let playingCell = currentPlayingIndex {
        if playingCell == indexPath.row {
            cell.playButton.currentImage = UIImage(named: "play_icon")
        } else {
            cell.playButton.setImage(UIImage(named: "pause_icon"), for: 
            .normal)
        }
    }
}

func playButtonTapped(cell : RadioCell) {
     if currentPlayingIndex == cell.tag {
        player.pause()
        self.pause = true
        currentPlayingIndex = nil
     } else { //IF PAUSE BUTTON
        loadRadio(radioURL : musicURL[cell.tag])
        currentPlayingIndex = cell.tag
     }
    tableView.reloadData()
 }


A: I suggested you to go with model based state management. let say you have a model to used to render tableview.
struct model {
 var videoURL:String?

   //Add a variable to handle UI
   var isVideoPlaying:Bool? = false
}


In tableview cell

func playButtonTapped(cell: RadioCell) {
    guard let indexpath = self.listRadioTavleView.indexpathForView(cell.playButton) else {
        return
    }
    If model[indexPath.row].isVideoPlaying {
        model[indexPath.row].isVideoPlaying = false
        // add  pausing video and button image changing code

    } else {
        model[indexPath.row].isVideoPlaying = true
        // add  playing video and button image changing code
    }
    self.listRadioTavleView.reloadData()
}

