0

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];
Eimantas
  • 48,927
  • 17
  • 132
  • 168
Damijan
  • 183
  • 1
  • 2
  • 7

2 Answers2

1

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.

Ole Begemann
  • 135,006
  • 31
  • 278
  • 256
0

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

JeremyP
  • 84,577
  • 15
  • 123
  • 161
  • Thaks! Sounds interesting! How should I make that? I have read the developer library about that, but I don't really have an idea, how to do that. I am quite new at programing with Obj C. – Damijan Sep 21 '11 at 09:29
  • @Damijan: http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/KeyValueObserving/Articles/KVOBasics.html#//apple_ref/doc/uid/20002252-178352 – JeremyP Sep 23 '11 at 10:51