0
votes

I'm having a problem with a custom NSPopUpButtonCell in a table that's instantiated when the table view is populated via bindings and a NSArrayController.

The pop up button cell is created but when attempting to access the outlet by overriding the pop up button cell's setMenuItem:item method it's nil.
Is this the expected behaviour..?
Should another method be used to replace the menu at creation time?

Basically I need the outlet to link back to my controller (NSWindowController) for that document window so I can customize the NSPopUpButtonCell menu accordingly from the custom popup button when it's populated.

A solution using bindings would be even better - but when overriding setObjectValue: I can see it's only never called with a nil parameter.. using a stock NSPopUpButtonCell results in a properly populated pop up menu, though.
(see also Why is NSPopUpButtonCell showing correctly when only setObjectValue:nil is called).

1
Is your popup button's menu also populated by bindings? If so, then you don't update it through an outlet, but by updating the array to which it is bound. - rdelmar
It is - but setObjectValue: is never called with valid content, it's always nil (see also Why is NSPopUpButtonCell showing correctly when only setObjectValue:nil is called). So how to get to the bound values from within the NSPopUpButtonCell..? - Jay
Maybe I'm not understanding your situation -- I don't really know what you mean by getting the values from within the popup button cell. Those values come from an array, so you should get the values from there. IF you can give a little more detail about what you're trying to do, it would be helpful. - rdelmar
Question rephrased - I suppose the question is how to populate the pop up button cell using bindings, i.e. what do we need to override. - Jay

1 Answers

1
votes

You don't need to override anything to populate an NSPopUpButtonCell in an NSTableView column. The thing to know is that you set the bindings on the NSTableColumn and not on the cell itself. Typically, you would have an NSArrayController in your xib that is bound to an NSArray containing all the options for the pop-up, and then you would select the column with the pop-up cell and go to it's bindings. Like in this screenshot (note the populated Content, Content Objects, and Selected Object bindings in the inspector on the right):

Screenshot of Xcode showing NSTableColumn bindings for pop-up cell column

If you want a working example, you can check out this project I whipped up for another StackOverflow question. There's a bunch of unrelated stuff pertaining to making the NSPopUpButtonCell use NSAttributedStrings, but the bindings in the xib constitute a working example of how to bind an NSTableColumn with a pop-up whose options are populated by bindings.