Вам нужно сохранить состояние каждой ячейки
class Service {
static let shared = Service()
var myTimerList = [TimerClass]()
}
//
здесь я добавил еще 2 переменные, почему осталось timerName
несмотря на то, что вы должны их инициализировать одинаковопоскольку current
будет содержать изменяющееся значение
class TimerClass {
let timerSecond : Int
let timerName : String
var current: Int
var isPlaying = false
init(second:Int, name:String) {
timerSecond = second
timerName = name
current = second
}
}
//
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "myCell", for: indexPath) as! TimerTableViewCell
let item = Service.shared.myTimerList[indexPath.row]
cell.tag = indexPath.row // to access the array inside the cell
if item.isPlaying {
cell.play() // add play method to the cell it has same button play action
}
else {
cell.timer?.invalidate()
}
cell.timerName.text = item.timerName
cell.secondLeftLabel.text = "\(item.current)"
return cell
}
//
внутри ячейки при нажатии кнопки, измените свойство isPlaying наtrue и false при остановке, подобной этой
// here self is the cell itself
Service.shared.myTimerList[self.tag].isPlaying = true
, а также при изменении отметок таймера
Service.shared.myTimerList[self.tag].current = // value