使用ArrayController中的Binding对NSScrollView,NSTableView的内容进行排序

时间:2013-01-10 08:13:57

标签: objective-c binding nsarraycontroller nsscrollview nssortdescriptor

我有NSScrollViewArrayController绑定。我需要按字母顺序对内容进行排序。我试图用绑定做到这一点,但我找不到合适的东西来绑定。我在sortDescriptor上使用了以下ArrayController

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

我是否会错过这个过程中的一个步骤,或者我甚至不接近对内容进行排序?

1 个答案:

答案 0 :(得分:0)

您尝试过FilterPredicate吗?这是一个示例代码:

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]];