Pregunta

I have a NSTimer and a NSSlider in my app. How do I make, that the time interval of the timer would respond instantly to the slider value?

For now it responds just at the beginning. Once the timer is already fired, it doesn't respond any more...

[NSTimer scheduledTimerWithTimeInterval:[slider doubleValue]
                                 target:self
                               selector:@selector(updateTextFieldWithRandomNumber)
                               userInfo:nil
                                repeats:YES];
¿Fue útil?

Solución

What about putting a KVO observation on the slider's doubleValue property and invalidating the timer and recreating it when the notification happens?

Otros consejos

You cannot change the time interval of a timer once you have created it. You have to invalidate the old timer and create a new one with the new time interval.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top