Make NSTableView active
cocoa, macos, nstableview, nstextfield, objective-c
Solution
Never call `becomeFirstResponder` directly. Use NSWindow's `makeFirstResponder:`
[[resultsTableView window] makeFirstResponder:resultsTableView];
Problem
Cocoa noob here. I've got a simple Mac app that includes an NSTextField that fetches some results and puts them into an NSTableView. I'd like to be able to press up/down while in the text field to activate the first/last item in the table view. I've done the following: ``` - (void)keyUp:(NSEvent *)theEvent { switch([theEvent keyCode]) { case 125: { NSLog(@"I need to move down"); NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:0]; [resultsTableView selectRowIndexes:indexSet byExtendingSelection:NO]; [resultsTableView becomeFirstResponder]; break; } case 126: { NSLog(@"I need to move up"); NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:[results count]-1]; [resultsTableView selectRowIndexes:indexSet byExtendingSelection:NO]; [resultsTableView becomeFirstResponder]; break; } } } ``` Which is partially what I want. It does select the first or last item in the `resultsTableView`, but the selected item stays grayed out, and the textview stays active. I thought calling `becomeFirstResponder` on the `resultsTableView` would do the trick, but it didn't. Any help would be greatly appreciated!