• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: triggerChangeNotificationsForDependentKey in subclass of NSArrayController
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: triggerChangeNotificationsForDependentKey in subclass of NSArrayController


  • Subject: Re: triggerChangeNotificationsForDependentKey in subclass of NSArrayController
  • From: Gabriele de Simone <email@hidden>
  • Date: Thu, 7 Oct 2004 16:15:36 -0400

On Oct 7, 2004, at 2:45 PM, Shaun Wexler wrote:

On Oct 7, 2004, at 10:44 AM, Gabriele de Simone wrote:

I think you are misunderstanding what automaticallyNotifiesObserversForKey: does. If you return NO, you are just declaring the intention to call willChangeValueForKey: and didChangeValueForKey: yourself (which is what I am doing in the example). Even if I change my code to return YES for myKey (from automaticallyNotifiesObserversForKey: of course), the notification for the dependent key is not sent.

Again, the point of the question is not that I don't want to call rearrangeObjects, but to understand why the notification is not being triggered.

See, the way Cocoa bindings knows that myKey changed is because it substitutes a subclass of your class, somewhat transparently to the runtime, and overrides your method -setMyKey: thus vectoring it thru a notification method which wraps your actual method IMP with the will/did change notifications, as well as any dependent notifications. The only way Cocoa bindings can issue these dependent notifications for you is if you DON'T disable them by returning NO when it queries your class... returning YES from the method +automaticallyNotifiesObserversForKey: tells the bindings layer it is okay to take care of this for you, as I've described above.

Shaun, you are not reading my messages. You just lectured me about returning YES from automaticallyNotifiesObserversForKey: when my statement should have given you the clue that that's not the issue here: "Even if I change my code to return YES for myKey (from automaticallyNotifiesObserversForKey: of course), the notification for the dependent key is not sent."

If you want to override this behavior, simply return NO and issue your own notifications. This is why it's not working for you; you've disabled notifications, including dependent ones. There's nothing wrong with this, other than now you have to do everything yourself in -setMyKey:

Again, you propose as the solution exactly what I am *already* doing, ignoring the fact that I just claimed that my code isn't working that way. I appreciate your good intentions, though.

The bottom line is: when talking about a subclass of NSArrayController, automatic notifications for dependent keys do not seem to be working according to the documentation. In other words, the strategy that works in your run-of-the-mill KVC-compliant class appears to fail for subclasses of NSArrayController.

I have posted a sample project here:
http://homepage.mac.com/gabrieledesimone/Steel/FaultyTrigger.zip

The subclass of NSArrayController exposes two additional keys, both of which should trigger a change notification for the dependent key "arrangedObjects". For one key, we ask the bindings layer to let us provide manual change notifications, and use willChange... and didChange... in the setter method. For the second key, we ask the Bindings layer to provide automatic notification. Launch the app, and notice that neither one of the two checkboxes, bound to these keys, trigger an update of the NSTableView. Click the button at the bottom of the window to refresh the contents manually (and verify that in fact the boolean values affect how objects in the array are filtered).

I hope everything should be beyond confusion now.

Gabriele

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
References: 
 >triggerChangeNotificationsForDependentKey in subclass of NSArrayController (From: Gabriele de Simone <email@hidden>)
 >Re: triggerChangeNotificationsForDependentKey in subclass of NSArrayController (From: Shaun Wexler <email@hidden>)
 >Re: triggerChangeNotificationsForDependentKey in subclass of NSArrayController (From: Gabriele de Simone <email@hidden>)
 >Re: triggerChangeNotificationsForDependentKey in subclass of NSArrayController (From: Shaun Wexler <email@hidden>)

  • Prev by Date: Re: small notes on enabling of menus in a modal window
  • Next by Date: Re: Selection and insertion point handling w/ NSTextAttachments
  • Previous by thread: Re: triggerChangeNotificationsForDependentKey in subclass of NSArrayController
  • Next by thread: Re: triggerChangeNotificationsForDependentKey in subclass of NSArrayController
  • Index(es):
    • Date
    • Thread