1

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];
    }
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579

1 Answers1

2

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.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • so basically else { // invalidate before NIL [self.myTimer invalidate]; self.myTimer = nil; // shoot method for next question count = 0; – onceuponaduck Sep 08 '16 at 12:59
  • Haha woah. Didn't see that coming mate. It works! Thank you VERY much! This problem had me questioning my future as dev. JK. – onceuponaduck Sep 08 '16 at 19:02
  • Glad I could help. Don't forget to accept an answer that solves your question. – rmaddy Sep 08 '16 at 19:04