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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to