Dia Dia - 23 days ago 19
Swift Question

Update custom tableviewcell label through NSTimer every 1 second in Swift 3

I have a custom

TableViewCell
.
I want the timer Label in each cell to decrease every second. I have referred to this link. The only problem is I am unable to change the Label's text. If I print it in the console, the value is coming fine. How can I reload the
TableView
after changing cell's value from custom cell class?
I am new to custom
TableView
cells so please help.
I have referred to this link too.

class CustomCell: UITableViewCell {

@IBOutlet weak var timerLabel: UILabel!

var timer = Timer()

func updateRow(){
print("started timer")
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(CustomCell.decreaseTimer), userInfo: nil, repeats: true)
}

func decreaseTimer(){
let cell = self
let timerVal = cell.timerLabel.text
print("decrease "+timerVal!)
//how to reflect this timerVal value in the cell?
}}

Answer

You need to assign update time value to label .

func decreaseTimer(){
    let cell = self
    let timerVal = cell.timerLabel.text
    print("decrease "+timerVal!)
    //how to reflect this timerVal value in the cell?
    cell.timerLabel.text = timerVal 
}}