• 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: KVO and master-detail NSTableViews
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: KVO and master-detail NSTableViews


  • Subject: Re: KVO and master-detail NSTableViews
  • From: Keary Suska <email@hidden>
  • Date: Thu, 4 Jun 2009 08:18:53 -0600

On Jun 4, 2009, at 4:24 AM, Stefan Reitshamer wrote:

I'm getting flaky behavior from my KVO code and I'm wondering what I'm doing wrong. I can't find any similar examples.

I have a pop-up button and 2 NSTableViews.
The pop-up button selection controls the content of the left NSTableView. The left NSTableView's selection controls the content of the right NSTableView.


The pop-up button and NSTableViews are bound to separate NSArrayControllers.
Each NSArrayController is bound to a separate NSMutableArray property in my app controller.
My app controller observes "selectionIndex" in the pop-up button's NSArrayController and "selectedObjects" in the left NSArrayController.


On startup, the pop-up button is populated, which causes a call to observeValueForKeyPath:ofObject:change:context:. This sets the left NSMutableArray, which in turn causes another (nested) call to observeValueForKeyPath:ofObject:change:context:, which sets the right NSMutableArray.

There seems to be a race condition -- sometimes the left table view is populated, sometimes the right, sometimes none. Each time I edit the nib, the behavior changes.

If your code depends on the order that objects in the nib are initialized, this may be the reason for unexpected behavior. Some changes to a nib might effect this loading order, which should be considered non-deterministic anyway.


Is this a bogus way to implement the dependent NSTableViews?
What's the right way?


If it is not necessary to route all the controller's content through the app controller, you may have better luck hooking the controllers together. Refer to this: <http://developer.apple.com/documentation/Cocoa/Reference/CocoaBindingsRef/BindingsText/NSArrayController.html#//apple_ref/doc/uid/NSArrayController-DontLinkElementID_24 >
in particular the "contentObject" binding.


RightTVController contentObject --> LeftTVController.selection.array_key_path
LeftTVController contentObject ---> PopUpController.selection.array_key_path


Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >KVO and master-detail NSTableViews (From: Stefan Reitshamer <email@hidden>)

  • Prev by Date: XIB and AppleGlot
  • Next by Date: How to lock an object?
  • Previous by thread: KVO and master-detail NSTableViews
  • Next by thread: Re: KVO and master-detail NSTableViews
  • Index(es):
    • Date
    • Thread