-6

Possible Duplicate:
How do I use NSTimer

I'd like to create a timer: When a user clicks a button the timer starts. After (e.g) two seconds the timer stops/resets and an action is performed.

I've been looking at NSTimer without any luck finding the right methods to use, and how to set this up the right way.

In advance, thanks for any help!

Community
  • 1
  • 1
Cake
  • 109
  • 1
  • 9
  • 3
    Did you read *[Timer Programming Topics](https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/Timers/Timers.html#//apple_ref/doc/uid/10000061-SW1)*? – rob mayoff Feb 16 '12 at 10:46

1 Answers1

2
- (IBAction)buttonPressed:(id)sender
{
    [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(timerExpired) userInfo:nil repeats:NO];
}

- (void)timerExpired
{
    NSLog(@"Your two seconds are up!");
}
bneely
  • 9,083
  • 4
  • 38
  • 46
  • @Dan The objective is not to call NSLog, but instead to demonstrate how to create a one-shot NSTimer as the question states. Do you have an example that you recommend instead? Share your answer. – bneely Apr 21 '15 at 02:21