2016-11-16 40 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 
}}