NSTimer not working while dragging a UITableView

Viewed 4278

I have an application with a countdown timer. I've made it with a label that is updated with a function called from a timer this way:

...
int timeCount = 300; // Time in seconds
...
NSTimer *myTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(actualizarTiempo:) userInfo:nil repeats:YES];
...
- (void)actualizaTiempo:(NSTimer *)timer {
    timeCount -= 1;
    if (timeCount <= 0) {
        [timer invalidate];
    } else {
        [labelTime setText:[self formatTime:timeCount]];
    }
}

Note: formatTime is a function which receive an integer (number of seconds) and returns a NSString with format mm:ss

Everything works ok, that is, the time counts down but the problem is that I have a UITableView in the application and if I touch the table and drag it (to move along the cells) the timer stops until I release my finger from the screen...

Is this behavior normal? If it is, is there any way to avoid it and make the timer work while dragging the table?

4 Answers

Swift version 4+:

var timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(self.TimerController), userInfo: nil, repeats: true)
RunLoop.main.add(timer, forMode: RunLoopMode.commonModes)

if you want to repeat for example as a counter then set repeat = true else = false

Related