Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a NSView get focus/first responder immediately to accept a mouseDown event?

I have an app with 2 separate NSWindow loaded.

Each window has one small table with two items in it.

Here's the problem i cant seem to solve -->

If window #1 is active/focused, i can click on the individual rows in the table normally. But if i want to click the rows in the table within window #2, I have to click the table twice. The first click to get Window #2 in active/focused, and finally the second click to actually select the row.

How can i get to select the rows in the NSTableViews in only one click (regardless if their windows are in focus or not) ?

like image 705
Just a coder Avatar asked Dec 26 '22 18:12

Just a coder


2 Answers

I sub-classed the NSTableView.

-(BOOL)acceptsFirstMouse:(NSEvent *)theEvent {
   return YES;
}
like image 169
Just a coder Avatar answered Dec 28 '22 10:12

Just a coder


Create an IBOutlet of your NSTableView as:

IBOutlet NSTableView* yourTable;

Bind it to your table.

Then use:

[window2 makeFirstResponder: yourTable];
like image 28
Neha Avatar answered Dec 28 '22 08:12

Neha