NSCollectionView stealing focus when selectable=YES

306 views Asked by At

I have an NSView created in Interface Builder with two controls in it, an NSCollectionView and an NSTableView. When my app runs and attaches this view to the window, the focus will correctly be set on my table view and highlight the appropriate row. However as soon as I call

[collectionView setSelectable:YES];

The focus will jump to my NSCollectionView and away from the tableview. The only way to get the focus back on my table view is to click on it with the mouse.

Neither of the following lines of code work

[tableView becomeFirstResponder];
[[self.view window] makeFirstResponder:tableView];

Anyone have any ideas? This happens if I set the collectionview to selectable in IB as well.

1

There are 1 answers

0
seanalltogether On

Ok this code seems to "fix" it, but it still seems like a terrible hack. I noticed that if i set it selectable after a period of time it wouldn't steal focus, so now i do

-(void) loadView {
    [super loadView];
    [self performSelector:@selector(responderFix) withObject:nil afterDelay:0];
}
-(void) responderFix {
    [collectionView setSelectable:YES];
}