Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I update my NSTimer as I change the value of the time interval

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.

like image 674
cgossain Avatar asked Oct 21 '10 15:10

cgossain


1 Answers

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];
like image 155
Ben Avatar answered Oct 17 '22 13:10

Ben