Array Controller notifications

Hello,

Is there a way to know when the selection change in the content array of a controller? What’s the best (or simply possible) way?

a) detect a click into the view?
b) add an observer to know if selection changes?
c) use the notification system?

thank you!

a) then you need a keyboard up too if someone navigates with the arrow keys. Some prefer this because when you change the selection in your code none of the both notifiations will be triggered

b) This is the standard method to get a notification every time the selection has changed.

c) Don’t see why should make a custom notification

So I tried this:

    current application's NSWorkspace's workspaceClass's sharedWorkspace()'s notificationCenter()'s addObserver_selector_name_object_(me, "theSelectionHasChanged:", "tableViewSelectionDidChange", missing value)

. long line actually, and there is something wrong in it:

[<NSWorkspace 0x7fff70e5dec0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key workspaceClass. (error -10000)

But what ? :confused:

it is not tableViewSelectionDidChange but it is NSTableViewSelectionDidChangeNotification

there’s no notification subscription needed
just connect the delegate of the table view with your controller class and implement

- (void)tableViewSelectionDidChange:(NSNotification *)aNotification

of NSTableViewDelegate Protocol

What’s with the “workspaceClass’s”? There is no such thing. That’s what the error message is telling you – that NSWorkspace doesn’t know about “workspaceClass”. You should just remove that if you want to use this notification center.

However, you should be using NSNotificationCenter’s defaultCenter rather than the one in NSWorkspace if you are observing notifications sent within your app. The NSWorkspace one is to observe things that happen outside your app.
From the docs on NSWorkspace notifications:

So, if you want one of these, then use NSWorkspace, otherwise use NSNotification center.

Ric

Stefan,

That was my first idea: light and smart. but never fired.

I have waited for my NSArrayController to send this notification, not the table view. Now it works. In fact, it works too well: this notification is sent at each insertion as I fill the array. Is there a way to filter only selection change by mouse/key down? Maybe in the NSAppleEvent?

Regards,

PS. Thank you, Ric, for your precisions, as usual I keep every post preciously – one day or another I’ll surely come back to them.