0
votes

The data I'm attempting to display in the NSTableView is a list of files in a specific local directory.

In the code I have a method A which accesses the directory and loops through the files, adding a NSMutableDictionary containing details about each file to a NSMutableArray via addObject:, and returning that array. These details are not instance variables or properties of a model, each is just an NSString whose value is determined at runtime.

A separate method B invokes method A, and loops through the returned array, adding each item to my NSArrayController via addObject:.

In my .xib file I have a NSArrayController that is bound to the NSMutableArray instance variable in my code where all the info for the files in that specific local directory are stored.

I've also bound the value of each table column in the NSTableView to the relevant Model Key Path of the NSArrayController.

Running the app correctly displays the number of rows in the NSTableView (the correct number of files in that specific local directory). However, the text displayed in each table column (in all of them, in each individual table cell) is just "Table View Cell".

I've used NSLog to confirm that adding objects to the NSArrayController also updates the NSMutableArray instance variable it is bound to. I can also randomly look at objects stored in the instance variable, and access the details for that file via the same Model Key Path as specified in the bindings for each table column - yet the NSTableView does not display that information.

Any clues about what is causing this problem?

EDIT: I've also tried refreshing the NSTableView directly, via reloadData, without success.

In case it's relevant, the NSMutableArray instance variable tied to the NSArrayController is only ever populated by the NSArrayController. In other words, I don't add objects to that array in the code directly.

2

2 Answers

2
votes

The problem in this case ended up being the "Content Mode" setting of the NSTableView, which is specified in the Attributes inspector.

The default setting is apparently "View based" but needed to be "Cell based". After making this change and rebuilding, voila! it worked.

1
votes

The issue seems like, your table view is not refreshing. So use below line of code:-

[self.arrController rearrangeObjects];