Re: KVO and master-detail NSTableViews
Re: KVO and master-detail NSTableViews
- Subject: Re: KVO and master-detail NSTableViews
- From: Ken Thomases <email@hidden>
- Date: Thu, 4 Jun 2009 12:07:37 -0500
On Jun 4, 2009, at 5: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.
I think you're manually using KVO when you could (and perhaps should)
be using bindings. I also think you're setting up the observations in
the wrong direction. I wouldn't have the app controller observe
properties of the array controller. Mediating controllers should bind
to (thus, implicitly observe and set) properties of the coordinating
controller (or the model, reached through the coordinating controller).
First, I don't know if you need the array controller for the pop-up to
manage the selection. I think you should bind the pop-up's
selectedObject to a (possibly new) property on the app controller.
This may require use of both the content and contentObjects bindings
of the pop-up to get selectedObject to be an appropriate object.
Second, I think the array controller for the left table would bind to
or through this property (the one bound to the pop-up's selection) on
the app controller.
Lastly, the array controller for the right table would bind through
the selection property of the array controller for the left table.
Put another way, bindings are meant to reduce or eliminate glue code.
You seem to be reproducing the sort of glue code that one would
typically have in the pre-bindings days, just using KVO (and maybe
bindings themselves) to trigger the glue code.
Regards,
Ken
_______________________________________________
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