views:

21

answers:

1

I have an NSTtimer implemented and it's working fine. I also have the time interval argument connected to a UISlider for the iPhone. However when I change it's value the NSTimer is still running at the original time interval it does not get updated. How can I implement an NSTimer and have it change it's time interval as the value of my UISlider changes. Below is the line I am using for the NSTimer.

[NSTimer scheduledTimerWithTimeInterval:mySlider.value target:self selector:@selector(myMethod) userInfo:nil repeats:YES];

I want it to constantly update it time interval with the value of the UISlider

+2  A: 

You can't I'm afraid. Invalidate it with:

[myTimer invalidate];

Then create a new one with the new time. You may have to set it to nil first as well.

myTimer = nil;
myTimer = [NSTimer scheduledTimerWithTimeInterval:mySlider.value target:self selector:@selector(myMethod) userInfo:nil repeats:YES];
Ben
do you think that this is the way to go if I want to implement a strobe light mode to to turn on and off the iPhone 4 LED
cgossain
If you want a variable timer it is. Think about the possibility of having two timers offset from each other as well, although that may not work for your application.
Ben
great well thanks for your help, i'll see if i can get it working.
cgossain
dont forget to release (if necessary)
willcodejavaforfood