• 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: Using bindings to make an NSPopupButton to assign an array filter predicate
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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: James Farwell <email@hidden>
  • Date: Mon, 18 Dec 2006 10:58:15 -0800


On Dec 18, 2006, at 10:40 AM, Matt Neuburg wrote:

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>





Right you are. Since all the basic bindings tutorials I had read were covering table views I made the mistake of assuming that all the behind-the-scenes magic that occurs when you bind a table view column to a controller (which must somehow set up a reverse binding so that the controller can observe the table view's selection changes) also worked for popup buttons. Thanks for the response!

- James

_______________________________________________

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


References: 
 >Re: Using bindings to make an NSPopupButton to assign an array filter predicate (From: Matt Neuburg <email@hidden>)

  • Prev by Date: Fake escape key event
  • Next by Date: Re: PDFMarkupAnnotations!?
  • Previous by thread: Re: Using bindings to make an NSPopupButton to assign an array filter predicate
  • Next by thread: Re: Using bindings to make an NSPopupButton to assign an array filter predicate
  • Index(es):
    • Date
    • Thread