• 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: Binding a NSArrayController to a NSPopupButtonn & NSTextField
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Binding a NSArrayController to a NSPopupButtonn & NSTextField
      • From: John Joyce <email@hidden>
References: 
 >Binding a NSArrayController to a NSPopupButtonn & NSTextField (From: Eric Gorr <email@hidden>)

  • Prev by Date: Re: How to use NSManagedObjectContext, NSManagedObjectModel, NSEntityDescription, NSManagedObject
  • Next by Date: [solved] Re: NSImage leaks open file in 10.8.2?
  • Previous by thread: Binding a NSArrayController to a NSPopupButtonn & NSTextField
  • Next by thread: Re: Binding a NSArrayController to a NSPopupButtonn & NSTextField
  • Index(es):
    • Date
    • Thread