NSTimers Skipping?

Discussion in 'iOS Development' started by Steaps, Feb 5, 2009.

  1. Steaps

    Steaps New Member

    Joined:
    Oct 24, 2007
    Messages:
    5,074
    Likes Received:
    41
    Device:
    iPod touch
    This is where the timer is created:
    Code:
    	time = 5;
    	timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(showSecond:) userInfo:nil repeats:YES];
    And the action (selector:
    Code:
    - (void)showSecond:(id)sender {
    	NSLog(@"%f",time);
    	if (time == 0) { 
    		[self hideToolBar];
    		[timer invalidate];
    	}
    	time = time - 1;
    }
    I don't know why, but this timer skips. It goes fast, and repeats the # 5. Here is the NSLog report:
    Code:
    2009-02-05 15:31:58.688 TheBrowser[580:20b] 5.000000
    2009-02-05 15:31:59.688 TheBrowser[580:20b] 5.000000
    2009-02-05 15:31:59.768 TheBrowser[580:20b] 4.000000
    2009-02-05 15:32:00.687 TheBrowser[580:20b] 3.000000
    2009-02-05 15:32:00.768 TheBrowser[580:20b] 2.000000
    2009-02-05 15:32:01.687 TheBrowser[580:20b] 1.000000
    2009-02-05 15:32:01.768 TheBrowser[580:20b] 0.000000
    2009-02-05 15:32:02.687 TheBrowser[580:20b] -1.000000
    2009-02-05 15:32:03.687 TheBrowser[580:20b] -2.000000
    2009-02-05 15:32:04.687 TheBrowser[580:20b] -3.000000
    2009-02-05 15:32:05.687 TheBrowser[580:20b] -4.000000
    2009-02-05 15:32:06.687 TheBrowser[580:20b] -5.000000
    Notice how fast the timer goes, as well as it doesn't stop at 0, it used to, not sure whats wrong now.

    Thanks, Stephen.

    EDIT: I was calling the action that the timer was declared in twice.

Share This Page