onceuponaduck
onceuponaduck

Reputation: 75

Progress View LOOP

I want this progress view to basically "reset" when its done.

Tried to reset the count to 0 and it does reset but for each reset the timer just becomes faster and faster.

.h

@property (nonatomic, strong) NSTimer *myTimer;
@property (weak, nonatomic) IBOutlet UILabel *progressLabel;

.m

- (void)updateUI:(NSTimer *)timer
{
    static int count = 0; count++;

    if (count <=100)
    {
        self.progressView.progress = (float)count/100.0f;
    }
    else
    {
        self.myTimer = nil;
        [self.myTimer invalidate];
        // shoot method for next question
        count = 0;

    self.progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];

    self.progressView.center = self.view.center;
    [self.view addSubview:self.progressView];

    self.myTimer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(updateUI:) userInfo:nil repeats:true];
    }
}

Upvotes: 1

Views: 102

Answers (1)

rmaddy
rmaddy

Reputation: 318774

You need to invalidate the timer before you set it to nil. As of now, your call to invalidate is a no-op. This means you keep adding more and more active timers.

Upvotes: 2

Related Questions