NSTimer внутри пользовательского tableViewCell
Я активирую функцию в своем собственном классе ячеек из viewController. Пользовательский класс ячейки выглядит следующим образом:
import UIKit
class TableViewCell: UITableViewCell {
var counter = 10
class func timerStarted(){
var timer = NSTimer()
timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: "update", userInfo: nil, repeats: true)
}
class func update(){
let cell = TableViewCell()
var count = cell.counter
count = --count
println(counter)
}
}
Проблема в том, что переменный счетчик не изменяется, поэтому 9 печатается через каждый интервал. Как мне сделать так, чтобы он каждый раз менял значение и вел обратный отсчет?
Мы ценим любые предложения.
РЕДАКТИРОВАТЬ: я использую распознаватель жестов длинным нажатием, чтобы вызвать функцию, поэтому я не могу просто вызвать ее с помощью функции didSelectRowAtIndexPath. Мой код для длинного нажатия выглядит так:
func longPressActive(gestureRecognizer:UIGestureRecognizer) {
if (gestureRecognizer.state == UIGestureRecognizerState.Began) {
var point = gestureRecognizer.locationInView(self.tv)
if let indexPath = self.tv.indexPathForRowAtPoint(point) {
TableViewCell.timerStarted()
}
}
}