Detect which NSTableView is active

59 views Asked by At

I have an NSSplitView showing two NSTableView instances. I need to detect which table view has become "active" (of focused), which means the one that the user has clicked. I need to know that because each table view acts as a source list for another view that shows the content of the selected row(s). This other view is shared for both tables.

I could do it by subclassing NSTableView and reacting to mouseDown: or another method but it I'd rather avoid subclassing just for that. I also don't want to track any NSWindow event just to know if the user has clicked one of the tables (I'd rather subclass NSTableView).

Currently, I use the delegate method tableViewSelectionDidChange:, but this method is, obviously, only called when the selected row changes. I need to know that a table becomes active even if the selected row hasn't changed.

Observing the clickedRow property of the table views doesn't appear to work. If may not be KVO compliant.

Any ideas?

1

There are 1 answers

0
jeanlain On BEST ANSWER

For those interested, the most convenient solution I found was to take advantage of the fact that NSTableView is a subclass of NSControl. So just like NSButton it can send action messages when clicked (upon mouse up). For each tableView, I wired its "action" to the same ibaction selector of my controller object in interface builder. The controller identifies the sender and acts accordingly. No need to subclass NSTableView.