Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

davidlisburn

macrumors newbie
Original poster
Jan 11, 2010
1
0
Hi everyone

Im trying to make a time which will start and stop when i move a slider. So far i've managed to get the timer to start when i touch down on the slider but can't seem to find a way to have the timer stop once the slider gets to the max value or when i leave go of it. Any suggestions?

below is the code i've got so far.

thanks

Code:
- (IBAction)start{
	
myTicker = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(showActivity) userInfo:nil repeats:YES];
	
}


- (IBAction)reset{
	
	time.text = @"0";
}

- (void)showActivity {
	
	int currentTime = [time.text intValue];
	int newTime = currentTime + 1;
	time.text = [NSString stringWithFormat:@"%d", newTime];
	
	if (myslider.value == 100) 
	{
		[myTicker invalidate]; 
	}
 
An NSTimer is probably not what you want to use for this. It's designed to wait a certain amount of time and then fire off a message. I'd suggest you store the current date-time when the slider starts moving, update your time-interval as its moving, and then lock-down that time-interval as you reach maximum or the slider stops being updated.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.