11

我已经成功地按我的排序键对数据进行了排序lastName,但我想知道如何排序lastName,然后按firstName。这是我用来排序的代码lastName

NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"firstName" ascending:YES];
[request setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];

如何添加的辅助排序键firstName

4

2 回答 2

47
NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"firstName" ascending:YES];
NSSortDescriptor *sortDescriptor2 = [[NSSortDescriptor alloc] initWithKey:@"lastName" ascending:YES];

[request setSortDescriptors:[NSArray arrayWithObjects:sortDescriptor1, sortDescriptor2, nil]];
于 2011-12-07T05:07:17.227 回答
0

请注意,您正在传递一个排序描述符数组。只需为 firstname 创建另一个描述符并使用这两个描述符创建数组。它们将按数组的顺序应用。

于 2011-12-07T05:06:21.047 回答