0

I have an NSTableView, and I've used Interface Builder to bind its Content to an instance of an NSArrayController subclass. I have Controller Key set to arrangedObjects.

So far so good: If I just load an array of strings into my NSArrayController (using addObjects) and leave the Model Key Path blank, those strings show up in the table.

However, if I add an array of dictionaries to my NSArrayController, such that each dictionary has a name property, and I set Model Key Path to name, the table just shows a stringified version of the entire arrangedObjects array n times, where n is the length of the array. Indeed, this happens no matter whether Model Key Path is set to name, foo, or blank.

I just want the NSTableView to display the name property of each dictionary in arrangedObjects. What am I doing wrong?

Trevor Burnham
  • 76,828
  • 33
  • 160
  • 196

1 Answers1

2

Figured it out: In addition to binding the aforementioned NSTableView's Content (which turned out to be irrelevant), I'd bound the corresponding NSTableColumn's Value to have the controller arrangedObjects, with no Model Key Path. Setting that to name made everything work fine.

Trevor Burnham
  • 76,828
  • 33
  • 160
  • 196
  • Hi Trevor, I am running into the same problem you described above. In my case I have an array of dictionaries. I bound the array to arraycontroller in IB using Binding Inspector -> Controller contents and click on Bind to and point to File's owner. Then I went to NSTableColumn's Value to "Array controller". The Controller Key reads "arrangedObjects" and in Model Key Path I set it as "Path" which is key in the nsdictionary. Finally in NSTextField inside TableCellView I bind value to TableCellView with model Key path as objectValue. I get garbage. I dont know whats happening. Any ideas? – user2085689 May 05 '14 at 01:25
  • You are almost right. At the end, you said you bound the NSTextField inside your TableCellView (in newer XCode versions it may be a Table View Cell inside a different Table View Cell). Try to bind its parent (that is to say the TableCellView, not the final NSTextFIeld inside), choosing an empty Controller Key and "objectValue.Path" as a Model Key Path – Daladim Jul 16 '17 at 19:03