2016-11-16 65 views
0

我有一个自定义TableViewCell。 我希望每个单元中的定时器标签每秒减少一次。我已经提到了this的链接。唯一的问题是我无法更改标签的文字。如果我在控制台中打印它,价值会很好。如何在自定义单元类中更改单元格的值后重新加载TableView? 我是新来的自定义TableView单元格,所以请帮助。 我也提到了this链接。通过NSTimer在Swift 3中每1秒更新自定义tableviewcell标签

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? 
}} 
+0

你可以发布一些与tableView单元格和计时器相关的代码,所以我们可以得到想法和基于我们可以帮助你。 – CodeChanger

+0

我已经添加了CustomCell代码 – Mamta

回答

0

您需要将更新时间值分配给标签。

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 
}}