Skip to content

Instantly share code, notes, and snippets.

@sbrocket
Created May 27, 2011 04:01
Show Gist options
  • Select an option

  • Save sbrocket/994620 to your computer and use it in GitHub Desktop.

Select an option

Save sbrocket/994620 to your computer and use it in GitHub Desktop.
- (IBAction)buttonPressed:(id)sender {
if (timer == nil) {
seconds = 30;
timer = [[NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(updateCounter:)
userInfo:nil
repeats:YES] retain];
}
}
- (void)updateCounter:(NSTimer *)theTimer {
if (seconds > 0) {
--seconds;
} else {
seconds = 30;
[timer invalidate];
[timer release];
timer = nil;
}
self.myCounterLabel.text = [NSString stringWithFormat:@"%d", seconds];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment