2011-12-07 8 views
11

ソートキーlastNameでデータを正常にソートしましたが、ソート方法をlastName、次にfirstNameに分けています。ここで私は私がfirstNameの二次ソート・キーを追加するにはどうすればよいlastNameセカンダリNSSortDescriptorソートキーを確立するにはどうすればいいですか?

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

でソートするために使用されるコードはありますか?

答えて

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

[request setSortDescriptors:[NSArray arrayWithObjects:sortDescriptor1, sortDescriptor2, nil]]; 
+0

ここで検索を断念して尋ねると2秒後に、これは私が見つけた正確な解決策です。 [Listed Here](http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/SortDescriptors/Concepts/Creating.html#//apple_ref/doc/uid/20001845-BAJEAIEE) – tarheel

+0

ソリューションは@タールヒルを行った。リンクは死んでいる。 – new2ios

0

並べ替え記述子の配列を渡していることに注目してください。 firstnameの別のディスクリプタを作成し、両方のディスクリプタで配列を作成するだけです。それらは配列の順に適用されます。

関連する問題