0

I'm a relatively inexperienced Cocoa programmer who learns mostly by looking at sample code and trial and error, and I'm stumped by this one: I have a View-Based Table that is bound to an NSArrayController. Each of the columns has its view cell value bound to the Table Cell View's objectvalue.description keys.

The problem is that when I click a column heading to sort the table, the array does not update its order along with it. Since I've learned mostly by trial and error, there may be some fundamental concept I'm missing, but I've performed many searches and have come up with nothing. The closest result was here:

https://stackoverflow.com/questions/9280762/keep-nsarraycontroller-in-sync-with-sorted-nstableview

Shouldn't the bindings keep the array and the table in sync?

Community
  • 1
  • 1
tjf
  • 572
  • 5
  • 9

1 Answers1

1

No, it's the arranged objects of the array controller that are kept in sync with the table view -- when you sort a table you are sorting the array controller's arrangedObjects, not the array that provides the content to the controller.

rdelmar
  • 103,982
  • 12
  • 207
  • 218
  • Thanks! In an effort to keep the arrays in sync, I added the following method: `- (IBAction)clickTable:(id)sender { [characterArray setArray:[characterArrayController arrangedObjects]]; }` Is this a good way, or is there something that would be better? – tjf Apr 28 '12 at 18:20
  • I think that's fine as long as you want them sorted like they are in the table. – rdelmar Apr 28 '12 at 22:05