我有一個數組控制器與nextCheck(NSDate),lastName(NSString)和firstName(NSString)的鍵。我已經爲數組設置了排序描述符。正如你在下面看到的,我先通過nextCheck排序,然後是lastName,然後是firstName。這出現不工作,因爲NSDate不僅是一個日期組件,也是一個時間組件。有沒有簡單的方法來按日期組件排序?排序NSDate不考慮當天的時間 - 只是日期
[_arrayCurrentVisits setSortDescriptors:[NSArray arrayWithObjects:[NSSortDescriptor sortDescriptorWithKey:@"nextVisit" ascending:YES selector:@selector(compare:)],[NSSortDescriptor sortDescriptorWithKey:@"lastName" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)], [NSSortDescriptor sortDescriptorWithKey:@"firstName" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)], nil]];
感謝這兩個答案。我將使用其中之一。 – docwelch 2011-12-28 18:18:44