Re: Binding a NSArrayController to a NSPopupButtonn & NSTextField
Re: Binding a NSArrayController to a NSPopupButtonn & NSTextField
- Subject: Re: Binding a NSArrayController to a NSPopupButtonn & NSTextField
- From: Keary Suska <email@hidden>
- Date: Fri, 15 Feb 2013 09:21:13 -0700
On Feb 15, 2013, at 5:41 AM, Eric Gorr wrote:
> I have a NSArrayController filled with an array of NSDictionaries.
>
> [[self controller] addObject:@{ @"name" : @"itemA", @"part" : @"partA" }];
> [[self controller] addObject:@{ @"name" : @"itemB", @"part" : @"partB" }];
> [[self controller] addObject:@{ @"name" : @"itemC", @"part" : @"partC" }];
>
> I am populating a NSPopupButton with the items in this array based on the 'name' key. This is easily accomplished with the following bindings.
>
> Content Array binding -
> bound to: Array Controller
> controller key: arrangedObjects
>
> Content Values binding
> bound to: array controller
> controller key: arrangedObjects
> model key path: name
>
> I would then like to populate a NSTextField with the text in the 'part' key based on the current selection of the NSPopupButton. I have setup the following binding:
>
> Value binding
> bound to: array controller
> controller key: selection
> model key path: part
>
> With these bindings alone, the text field does display 'partC'.
>
> However, if I change the value of the NSPopupMenu, what the text field shows does not change.
It is useful to note that even though an object will bind to an NSArrayController, it does not mean that it will employ the controller's selection semantics. NSPopupButton is one of them, I believe. The "proper" way to do this is bind the NSPopupButton's selectedObject/Value to a controller that maintains the value (*not* the array controller), and then bind the NSTextField to that other controller. You may be able to use an NSObjectController in the xib to act as the "proxy" for the value, however kludgey.
HTH,
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
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