Skip to content

Instantly share code, notes, and snippets.

@mattpat
Created March 31, 2010 20:47
Show Gist options
  • Save mattpat/350868 to your computer and use it in GitHub Desktop.
Save mattpat/350868 to your computer and use it in GitHub Desktop.
#pragma mark Actions
- (IBAction)callMyMom:(id)sender
{
// Update the text view, disable the button
[textView insertText:@"Time to call Mom!\n"];
[self disableButton:sender];
// We're going to make an NSDictionary containing
// the button, so we can pass it to our timer
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:sender forKey:@"button"];
// Now we create a timer scheduled to fire in one second
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(reenableTimer:) userInfo:userInfo repeats:NO];
}
#pragma mark Button methods
- (void)enableButton:(NSButton *)theButton
{
[theButton setEnabled:YES];
[theButton setBezelStyle:NSRegularSquareBezelStyle];
}
- (void)disableButton:(NSButton *)theButton
{
[theButton setBezelStyle:NSTexturedSquareBezelStyle];
[theButton setBordered:YES];
[theButton setTitle:@"Called Mom"];
[theButton setEnabled:NO];
}
#pragma mark Timer handler
- (void)reenableTimer:(NSTimer *)theTimer
{
// Grab the button from our user info dict
NSButton *theButton = [[theTimer userInfo] objectForKey:@"button"];
[self enableButton:theButton];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment