• 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
NSPopUpButton bindings confusion: selectedIndex vs selectedObject vs contentValues etc
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSPopUpButton bindings confusion: selectedIndex vs selectedObject vs contentValues etc


  • Subject: NSPopUpButton bindings confusion: selectedIndex vs selectedObject vs contentValues etc
  • From: Niko Matsakis <email@hidden>
  • Date: Thu, 22 Sep 2005 11:50:07 +0200

I am terribly confused about what the bindings ought to be on an NSPopUpButton; I thought I had everything figured out, but I can never seem to get every piece working simultaneously.

Here is what I am trying to do:

1. Bind an NSPopUpButton to display the set of Relationship objects existing in my document (I am using CoreData)

2. Based on a property of the currently selected Relationship from that button, enable or disable other parts of the form.

3. Programmatically extract the represented Relationship object.

I can get 1 & 2, or 1 & 3, but not all three.

What I have done is to create an NSArrayController which is set to represent the Entity Relationship, with the appropriate managed object context.

The NSPopUpButton's bindings are:

content: RelationshipsController.arrangedObjects
contentValues: RelationshipsController.arrangedObjects.name
selectedIndex: RelationshipsController.selectedIndex

Meanwhile, other parts of the form have an enable binding like so:

enabled: RelationshipsController.selection.interlanguage

The intention is that when a Relationship that has the "interlanguage" property set to true is selected, the other parts of the form are enabled. This works fine, but I can't find a way to programmatically access the selected object. When I do, [[instance_of_NSPopUpButton selectedItem] representedObject] I get back an NSNumber with the selection index (0, 1, 2, etc) rather than the object. I also tried to obtain the selected object programmatically by doing [RelationshipsController selection], but that seems to return nil no matter what.

If I remove the selectedIndex binding, then I can programmatically access the selected Relationship by doing [[instance_of_NSPopUpButton selectedItem] representedObject]; the enabled binding, on the other hand, doesn't seem to respond when I change the selected item in the popup. It DOES set itself appropriately when I add or delete Relationships, but otherwise it pays no attention. This would seem to be a problem in the observer somewhere.

I tried binding selectedObject to RelationshipsController.selected, but that causes new entries to be added at the end of the list like "<_NSControllerProxy 0x123123>". I'm not really clear on why that is but I'm guessing that this proxy object is being returned, not being found in the list of objects, and thus added to the set of items displayed by the pop up button.

Am I going about this the right way? I don't understand why the binding of selectedIndex should affect the representedObject returned by the NSMenuItem; I'm assuming that the reason that the "enabled" binding doesn't work when selectedIndex is not bound is that changing the NSPopUpButton doesn't propagate back to the ArrayController and cause it to change its selection.

I'm wondering if I'm just unclear on what each binding for NSPopUpButton means; I've read the cocoa bindings reference, and the examples I found on http://homepage.mac.com/mmalc/CocoaExamples/ controllers.html, and that all seemed fairly clear.


thanks in advance, Niko _______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • SEMIFIXED - Re: NSPopUpButton bindings confusion: selectedIndex vs selectedObject vs contentValues etc
      • From: Niko Matsakis <email@hidden>
  • Prev by Date: Re: How to join NSScrollView and NSTableView programmatically
  • Next by Date: Re: Japanese Language Support
  • Previous by thread: NSTextView Custom Insertion Point
  • Next by thread: SEMIFIXED - Re: NSPopUpButton bindings confusion: selectedIndex vs selectedObject vs contentValues etc
  • Index(es):
    • Date
    • Thread