Note that there are some explanatory texts on larger screens.

plurals
  1. POBinding an NSPopupButton to an NSArrayContraller with NSManagedObject subclasses
    primarykey
    data
    text
    <p>There seem to be dozens of questions about binding a NSPopupButton, so I feel a little better about struggling so much with this, but none of them seem to fix my issue. </p> <p>I have an NSManagedObject subclass that has a one to many relationship with another class. Let's say Foo has a relationship to Bar, so Foo has a property that is an NSSet of Bars.</p> <p>I have created an NSArrayController and bound its contentSet to the Foo object and the 'bars' key path.</p> <p>I then bind my NSPopupButton's content to the array controller's arrangedObjects and its contentValues to the array controller's arrangedObject (controller key) and 'name' (the property on Bar that I want to display).</p> <p>This all works fine so far, but when I try to bind the NSPopupButton's selected object to the array controller's selection The NSPopupButton displays "&lt;_NSArrayControllerObjectProxy". I also tried adding 'name' as the keyPath for this binding, and this does make the NSPopupButton display the name correctly, but then when I change the selection in the popup the app thrown an exception:</p> <pre><code>Unacceptable type of value for attribute: property = "name"; desired type = NSString; given type = Bar; </code></pre> <p>I guess this makes sense, as the popup is trying to set the string value of 'name' as the selected Bar. I would think I would therefore need to bind a selected object and a selected value, but the XIB will disable selected value if I have a selected object set.</p> <p>I have also tried binding the selected value instead, and this half works (the array controller's selection does change) but the options in the popupmenu don't change to show the one that was deselected and hide the newly selected one).</p> <p>Failing all of this I read an article here: <a href="http://blog.chrisblunt.com/cocoa-bindings-and-nspopupbutton/" rel="nofollow">http://blog.chrisblunt.com/cocoa-bindings-and-nspopupbutton/</a> that says NSPopupButton "NSPopUpButton does not record the user’s selection" and to instead store your selection somewhere other than the array controller. I tried putting a currentBar property in my window and binding the selection to that instead, and although I can see that currentBar is changing (because I have another view bound to it also) the label in the popup button does not change.</p> <p>If anyone can help me out I'd be very appreciative.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload