1

I have a 45 seconds countdown made with a NSTimer which look like this:

-(IBAction)Start {
mainInt = 45;
timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(countDown) userInfo:nil repeats:YES]; }

- (void)countDown {
mainInt -= 1;
seconds.text = [NSString stringWithFormat:@"%i", mainInt];
if (mainInt == 0) {
    [timer invalidate];
}

Then i placed a simple UIProgressView in my storyboard. I tried linking both together without code but it's obviously not that easy. How can i link the UIProgressView to the NSTimer to make sure that the Progress bar gets full once the countdown reach 0?

1 Answers1

1

You can update your UIProgressView from the selector method of NSTimer

- (void)countDown
{
   mainInt                  -= 1;
   seconds.text              = [NSString stringWithFormat:@"%i", mainInt];
   yourProgressView.progress = (45 - mainInt)/45.0f;

   if (mainInt == 0)
   {
      [timer invalidate];
   }
}
Midhun MP
  • 103,496
  • 31
  • 153
  • 200
  • Thanks for the quick response. In my .h file, is the UIProgressView supposed to be between the curly brackets {} or below them? Also, is it an IBAction or IBOutlet? – user3763526 Jan 16 '15 at 22:35
  • @user3763526: Declare UIProgressView as an IBOutlet property and connect it in your storyboard. – Midhun MP Jan 16 '15 at 22:37