Search code examples
macoscocoaxcode6nsarraycontrollernssortdescriptor

NSArrayController sortDescriptors is not working


I'm have a NSArrayController (A) bind it to another NSArrayController (B) and I'm trying to sort the NSArrayController (B) but is not working.

Here is my code:

    NSSortDescriptor *bSortDescriptor = [[NSSortDescriptor alloc]
                                           initWithKey:@"name" ascending:YES];
    self.arrayControllerB.sortDescriptors = @[bSortDescriptor];

Does any of you knows why the NSSortDescriptor is not working?

I'll really appreciate your help.


Solution

  • After you change the sort descriptors, you need to invoke rearrangeObjects on the array controller. And then schedule whatever code you want to manipulate the sorted contents with dispatch_async.

    Based on my answer here. Hope this helps.