Skip to content

Instantly share code, notes, and snippets.

@augard
Forked from odrobnik/gist:4086204
Created November 16, 2012 10:22
Show Gist options
  • Save augard/4086223 to your computer and use it in GitHub Desktop.
Save augard/4086223 to your computer and use it in GitHub Desktop.
Forwarding keydown event to a search field
- (void)goToProductListWithEvent:(NSEvent *)event
{
self.selectedViewController = _productListViewController;
[self.view.window makeFirstResponder:_productListViewController.searchField];
_productListViewController.searchField.stringValue = [event characters];
int64_t delayInSeconds = 0.01;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
NSWindow *window = self.view.window;
NSText *fieldEditor = [window fieldEditor:YES forObject:_productListViewController.searchField];
[fieldEditor setSelectedRange:NSMakeRange(1, 0)];
[_productListViewController updateFilter:_productListViewController.searchField];
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment