Timer Question.

Discussion in 'iOS Programming' started by davidlisburn, Jan 11, 2010.

  1. davidlisburn macrumors newbie

    Joined:
    Jan 11, 2010
    #1
    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]; 
    	}
    
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    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.
     

Share This Page