Reputation: 81
My environment:
My Project:
A bit of background: I got an NSTableView with multiple columns all hooked into an NSArrayController, which in turn, is hooked up to core data (say entity "Car"). Everything works well - I can load and edit the column values, and save changes to sqlite. All of this is accomplished with bindings via Interface Builder. I now want to add a new "color" column to this table, representing a relationship to another entity, say entity "Color". Each row will have an NSPopUpButton for this new column; the pop-up button should have its values populated from a second NSArrayController linked to the "Color" entity. Thus, "color" is a many-to-one relationship between Car and Color (many Cars can reference a given Color), and I'd like the values in the pop-up button to correspond to the "name" property from Color.
What I've done:
In the storyboard (under the controller scene containing the Car table), I've added a second NSArrayController, "Colors Array Controller":
1) under "Attributes Inspector" -> Mode = Entity Name, Entity Name = Color, "Prepares Content" checkbox selected
2) under "Bindings Inspector" -> Parameters -> Managed Object Context -> "Bind To" checked -> selected "Cars Controller" -> Model Key Path = context
In the Cars table (under NSTableCellView), added an NSPopUpButton.
At this point, everything builds and runs properly, except that all the columns in the table show the "Item 1" default value from the pop-up button (I can also see the other default values when I expand the pop-up).
Now, I've tried the following in a futile attempt to load the pop-up with the correct values:
Strategy 1:
using Interface Builder, selected the NSPopUpButton. Under Bindings Inspector (Value Selection), checked "Bind to" and specified the Colors Array Controller from above; Controller Key -> arrangedObjects; Model Key Path -> name
Strategy 2:
For both of the strategies above, whenever I try to run (or just build) the project, Xcode hangs at "Compiling 1 of 1 Storyboard files". Activity Monitor shows that the "ibtoold" process steadily consumes all memory available (as soon as I kill it, Xcode reports my build as failed).
I would really appreciate if somebody could shed some light into what I'm doing wrong, or suggest alternatives to achieve the desired results.
Upvotes: 2
Views: 617
Reputation: 21361
I just ran into the same issue: As soon as I bind a NSPopupButton
's content
binding to an ArrayController
's arrangedObjects
Xcode will compile the storyboard forever. When I remove the binding it will compile as usual :(
Since my NSPopupButton
is inside a table column, I've removed the array controller and I'm now binding its content
directly to a property of the table column's object value.
Upvotes: 2