Created
November 16, 2012 10:20
-
-
Save odrobnik/4086204 to your computer and use it in GitHub Desktop.
Forwarding keydown event to a search field
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
- (void)goToProductListWithEvent:(NSEvent *)event | |
{ | |
self.selectedViewController = _productListViewController; | |
// make the search bar first responder | |
NSWindow *window = self.view.window; | |
[window makeFirstResponder:_productListViewController.searchField]; | |
// set the keyDown character into the search field | |
_productListViewController.searchField.stringValue = [event characters]; | |
// need to update filter because this didn't trigger the delegate method | |
[_productListViewController updateFilter:_productListViewController.searchField]; | |
// put the cursor to the right of the character, otherwise it is selected | |
NSText *fieldEditor = [window fieldEditor:YES forObject:_productListViewController.searchField]; | |
// do this on next run loop, otherwise it does not work | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
[fieldEditor setSelectedRange:NSMakeRange(1, 0)]; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment