Skip to content

Instantly share code, notes, and snippets.

@mattbischoff
Created January 31, 2014 02:48
Show Gist options
  • Save mattbischoff/8725806 to your computer and use it in GitHub Desktop.
Save mattbischoff/8725806 to your computer and use it in GitHub Desktop.
Receive UIKeyCommands without a text view or text field as the first responder.
@implementation TMDashboardViewController
#pragma mark - UIResponder
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (NSArray *)keyCommands {
static NSArray *keyCommands;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
UIKeyCommand *composeCommand = [UIKeyCommand keyCommandWithInput:@"c" modifierFlags:UIKeyModifierAlternate action:@selector(composeShortcut:)];
keyCommands = @[composeCommand];
});
return keyCommands;
}
#pragma mark - TMDashboardViewController
- (void)composeShortcut:(UIKeyCommand *)command {
[self compose];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment