Re: Using bindings to make an NSPopupButton to assign an array filter predicate
Re: Using bindings to make an NSPopupButton to assign an array filter predicate
- Subject: Re: Using bindings to make an NSPopupButton to assign an array filter predicate
- From: Matt Neuburg <email@hidden>
- Date: Mon, 18 Dec 2006 10:40:29 -0800
- Thread-topic: Using bindings to make an NSPopupButton to assign an array filter predicate
On Sun, 17 Dec 2006 16:34:25 -0800, James Farwell <email@hidden> said:
>Greetings,
>
>I am attempting to use Cocoa Bindings in an app for the first time
>and I'm running into a bit of a roadblock. I have a list of data
>that can be filtered a few different ways, and I would like to let
>the user select how it is filtered via an NSPopupButton in my
>preferences window. I have an NSArrayController (dataController)
>managing the list of data, and another NSArrayController
>(predicateController) managing an list of predicates that define the
>different ways to filter. I am trying to figure out how to set up
>the Cocoa Bindings in such a way that selecting a different item in
>the NSPopupButton will cause the dataController to immediately apply
>the new predicate as its filter. Here is what I have so far:
>
>
>predicateController (NSArrayController)
>-----
>contentArray
>Bind to: controllerAlias
>Controller Key: selection
>Model Key Path: predicates
>-----
>
>
>dataController (NSArrayController)
>-----
>contentArray
>Bind to: controllerAlias
>Controller Key: selection
>Model Key Path: data
>-----
>filterPredicate
>Bind to: predicateController
>Controller Key: selection.predicate
>-----
>
>
>NSPopupButton
>-----
>content
>Bind to: predicateController
>Controller Key: arrangedObjects
>-----
>contenValues
>Bind to: predicateController
>Controller Key: arrangedObjects
>Model Key Path: name
>-----
>selectedIndex
>Bind to: Shared User Defaults
>Controller Key: values
>Model Key Path: filter
>-----
>
>
>When I build/run this, the NSPopupButton populates properly, and my
>data shows up filtered by the first predicate in the list, regardless
>of which is selected. If I try to change the selection of the
>NSPopupButton, the visible data does not change.
>
>I can only assume that the NSPopupButton is not actually setting the
>"selection" of its content NSArrayController. My question is, does
>anyone know either how to get this scenario to work, or an example
>that does something very similar correctly.
Remember, bindings are basically nothing but observing (KVO). Thing A can
"see" Thing B change because (1) Thing A is observing Thing B and (2) Thing
B changes in a KVO-compliant way. So, in your scenario, what is observably
changing? You complain that when the user chooses from the NSPopupButton,
the predicateController's selection is not changing. Well, what would cause
it to change? You've bound the NSPopupButton's selectedIndex to the shared
user defaults - you've not connected it in any way to the
predicateController.
For the standard way of hooking things up, check the archives:
<http://www.cocoabuilder.com/archive/message/cocoa/2006/5/31/164724>
m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
<http://www.amazon.com/gp/product/0596102119>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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