NSTimer inside custom tableViewCell

后端 未结 2 1118
臣服心动
臣服心动 2021-01-24 16:45

I\'m activating a function in my custom cell class from a viewController. The custom cell class looks like this:

import UIKit

class TableViewCell: UITableViewCe         


        
2条回答
  •  醉酒成梦
    2021-01-24 17:21

    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        let cell = tableView.cellForRowAtIndexPath(indexPath) as TableViewCell
        cell.timerStarted()
    }
    

    For your tableview cell class:

    func timerStarted(){
        var timer = NSTimer()
    
        timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: "update", userInfo: nil, repeats: true)
    }
    
    func update(){
        counter = counter - 1
        println(counter)
    }
    

提交回复
热议问题