PDA

View Full Version : Getting keyboard selection change events in NSTableView




aliher
Apr 20, 2009, 06:37 AM
Hi,

I have a separate panel displaying properies of selected row in NSTableView (there are quite a number of them so editing right in table doesn't look like a good idea).
I'm subscribing to notification for selection change and when I receive it, I set the objects to edit for the property editor. This works fine until I start selecting rows using keyboard. In this case I never get any notifications, but I can see that selected row changes as a result of keyboard commands (via debug button which dumps required properties of controls :).
What would be a right way to get notifications for that kind of selection changes? I can thing of subclassing NSTableView and handling keyboard events. Is there any other more elegant way?

UPD: NSTableView's and NSOutlineView's delegate provide functionality that supersedes one provided by notification and notifies on keyboard selection changes. I've missed it when reading docs.



kainjow
Apr 21, 2009, 12:08 PM
So were you subscribing manually to the notifications instead of using the delegate method that is handled automatically? It seems odd since it should work either way.

aliher
Apr 21, 2009, 07:06 PM
So were you subscribing manually to the notifications instead of using the delegate method that is handled automatically? It seems odd since it should work either way.

Exactly. I first used notifications as already subscribed to other events. Delegate description says something about its method being notified as a result of notification. But the behaviour seems to be different. As soon as I changed method name and set object as delegate it started receiving all notification. Sounds a bit illogical for me, but it works.