Reputation: 797
I have a NSArrayController
with Objects (Mutable dictionaries) taht contain 2 values for each entry. The values are "keyword" and "order".
The NSArrayController
is bound to a NSTableView that has only one column and is displaying the "keyword" value.
I would need to sort the table based on "order".
NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"order" ascending:YES];
[keywordscontroller.arrangedObjects sortedArrayUsingDescriptors:[NSArray arrayWithObject:sort]];
But the order in the NSTableView
is not updating. what am I missing?
---EDIT ---
sample of how it is sorting:
Upvotes: 0
Views: 128
Reputation: 1784
You are not storing the result of your call to - (NSArray *)sortedArrayUsingDescriptors:(NSArray *)sortDescriptors
and so, you will never have access to it.
However, since you already are using an NSArrayController
, why not just use the - (void)setSortDescriptors:(NSArray *)sortDescriptors
method of your NSArrayController
and then reference the contents of the array using - (id)arrangedObjects
?
custom sort descriptor for string with numeric comparison
[keywordscontroller setSortDescriptor:[NSSortDescriptor sortDescriptorWithKey:@"order" ascending:YES comparator:^(id obj1, id obj2) {
return [(NSString *)obj1 compare:(NSString *)obj2 options:NSNumericSearch];
}];
Upvotes: 1