0
我想單擊單元格播放音頻。並更改按鈕image.They工作正常。但是當我滾動我的4單元格按鈕圖像自動change.Please幫助。任何幫助,將不勝感激。按鈕圖像重複單元格
@IBAction func playSong (_ sender : UIButton , event: UIEvent){
let buttonPosition:CGPoint = sender.convert(.zero, to: table)
let indexPath = self.table.indexPathForRow(at: buttonPosition)
let cell = table.cellForRow(at: indexPath!) as? CustumCell
let a = URL(string : "http://www.abstractpath.com/files/audiosamples/sample.mp3")
if((audioPlayers) != nil){
audioPlayers = nil
}
audioPlayers = AVPlayer(url: a!)
if sender.isSelected == false {
sender.isSelected = true
audioPlayers?.play()
cell?.play.setImage(UIImage(named : "homestop"), for: .normal)
}else{
sender.isSelected = false
audioPlayers?.pause()
cell?.play.setImage(UIImage(named : "homeplay"), for: .normal)
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let identifier = "CustumCell"
var cell: CustumCell! = tableView.dequeueReusableCell(withIdentifier: identifier) as? CustumCell
if cell == nil {
var nib : Array = Bundle.main.loadNibNamed("CustumCell",owner: self,options: nil)!
cell = nib[4] as? CustumCell
}
cell.reportView.isHidden = true
cell.play.tag = indexPath.row
cell.play.addTarget(self, action:#selector(playSong(_:event:)), for: .touchUpInside)
cell.homereport.tag = indexPath.row
cell.homereport.addTarget(self, action:#selector(showReportView(_:)), for: .touchUpInside)
return cell
}