Sort the contents of an NSScrollView, NSTableView,

2019-02-20 23:55发布

I have an NSScrollView wich is bound with an ArrayController. I need to sort the content alphabetically. I've tried to do this with bindings but I can't find the right thing to bind. I used the following sortDescriptor on my ArrayController.

[myArrayController setSortDescriptors:[NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"myKey" ascending:YES selector:@selector(compare:)]]];

Do I miss a step in the process or am I not even close to sorting the content?

1条回答
老娘就宠你
2楼-- · 2019-02-21 00:13

Did you try FilterPredicate ? this is a sample code:

NSDate *afterDate=[balanceDateAfter objectValue];
NSDate *beforeDate=[balanceDateBefore  objectValue];
NSComparisonResult duration=[beforeDate timeIntervalSinceDate:afterDate];

duration=duration/3600;
duration=duration/24;

[checkInBalanceArray setFilterPredicate:[NSPredicate predicateWithFormat:@"(checkDate >= %@) AND (checkDate <= %@)", afterDate, beforeDate]];

[checkOutBalanceArray setFilterPredicate:[NSPredicate predicateWithFormat:@"(checkDate >= %@) AND (checkDate <= %@)", afterDate, beforeDate]];
查看更多
登录 后发表回答