• 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: [SOLVED] bindings with two interdependent NSPopupButtons
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [SOLVED] bindings with two interdependent NSPopupButtons


  • Subject: Re: [SOLVED] bindings with two interdependent NSPopupButtons
  • From: "Justin R. Miller" <email@hidden>
  • Date: Thu, 28 Jun 2007 04:47:38 -0400

For posterity, I figured this out. The trick is to not only bind the NSPopupButton's contentValues to the array controller's arrangedObjects, but also to bind the button's selectedIndex to the array controller's selectionIndex. The former populates the popup button and the latter tracks the actual selection.

Most confusing, but makes sense looking back (ain't that always the way...)

Much thanks to http://sixthhappiness.ca/blog/2005/08-07/index.html

JM

On Jun 28, 2007, at 1:11 AM, Justin R. Miller wrote:

First, perhaps the subject is a bit misleading -- I understand that views can only be bound to controllers, not to each other. What I'm trying to do is make a property of one button contingent on the selection in the other button.

I have two NSPopupButtons, each bound to their own NSArrayController for content, and that's working fine.

What I want to happen is that the selection on #1 drives the enabled/disabled property on the other.

I have a value transformer registered and working, at least initially. It looks at the item selected in the first button and returns an NSNumber yes/no to drive the enabled property on the second button.

After the code that programmatically binds the contents of both buttons, I have this:

[secondPopupButton bind:@"enabled"
toObject:firstPopupButtonArrayController
withKeyPath:@"selectedObjects"
options:[NSDictionary dictionaryWithObjectsAndKeys:
@"MyValueTransformer", NSValueTransformerNameBindingOption,
[NSNumber numberWithBool:YES], NSContinuouslyUpdatesValueBindingOption]];


I have an NSLog in my value transformer. On awakeFromNib, I get the log message, but then never get it again when the first button's selection is changed, so naturally, the second button's enabled/ disabled state never changes.

I tried adding the second button as an observer to the first button's array controller. Nada.

I then tried subclassing the second button to put in my own call to observeValueForKeyPath:ofObject:change:context: -- also nothing.

Where am I going wrong?

--
Justin R. Miller
Code Sorcery Workshop
http://codesorcery.net


_______________________________________________

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:
40codesorcery.net


This email sent to email@hidden


-- Justin R. Miller Code Sorcery Workshop http://codesorcery.net


_______________________________________________

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: 
 >bindings with two interdependent NSPopupButtons (From: "Justin R. Miller" <email@hidden>)

  • Prev by Date: crash in NSNavOutlineDelegate (Martin Wierschin)
  • Next by Date: Re: CoreData predicate programming
  • Previous by thread: bindings with two interdependent NSPopupButtons
  • Next by thread: Creating a custom subclass of NSController
  • Index(es):
    • Date
    • Thread