views:

73

answers:

2

I have noticed in the Interface Builder if I want to click on or drag from the Library panel, I only have to click on it once, even if the Library panel does not have the current focus.

I am trying to build a panel that behaves similarly.

Is there any simple way to let the NSTableView accept the click, even if the window does not have the focus?

Thanks.

A: 

Your view should override -acceptsFirstMouse: to return YES (or evaluate the event passed to you to determine what to return). You'll have to subclass NSTableView to do that of course.

Rob Napier
I ended up not having to do that, but just setting the "becomesKeyOnlyIfNeeded" property of the Panel that the Table was in. But thank you for answering.
jeffp
+1  A: 

Ok, I found the answer. Inside from awakeFromNib I call this: [self setBecomesKeyOnlyIfNeeded:YES];

It seems to do the trick. It's a little bit different from Interface Builder where the Panel actually gets the focus simultaneously with a single click, but doing it this way is just what I was looking for.

jeffp
Glad it worked. My answer below will give you focus simultaneously with the click, and will work for any view, not just NSPanels. But if this meets your needs, then it's obviously much simpler, and doesn't steal keyboard focus from the current keyWindow (that's either good or bad, depending on your need).
Rob Napier
Did you have to set anything else in either the XIB file, or in code? I'm trying to get this to work with an NSCollectionView, and am so far failing entirely.
Ben Gottlieb
Sorry for taking so long to respond... I just noticed this comment. Did you try "setBecomesKeyOnlyIfNeeded"? Did it not work?
jeffp