Created
March 31, 2010 20:47
-
-
Save mattpat/350868 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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