私のアプリでは、別の日に単語をブックマークしています。並べ替えのオプション(最近の並べ替えや最初の古いものなど)があります。ブックマークされた日付に基づいて単語を並べ替えることができません。どうすればいいですか?ディスクリプタを使用することで、最初の2つのエントリだけがソートされるので、ソートはうまくいかない。私のコードは次のとおりです。目的地Cで日付をソートする方法は?
NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"cellType" ascending:NO selector:@selector(localizedCaseInsensitiveCompare:)];
NSSortDescriptor *sortDescriptor2 = [[NSSortDescriptor alloc] initWithKey:@"entrydate" ascending:NO selector:@selector(localizedCaseInsensitiveCompare:)];
NSArray *sortDescriptors = [NSArray arrayWithObjects:sortDescriptor1, sortDescriptor2, nil];
[self.favoriteEntries sortUsingDescriptors:sortDescriptors];
[[NSUserDefaults standardUserDefaults] setValue:@"descendingDate" forKey:@"BookmarkSortType"];
の代わりにlocalizedCaseInsensitiveCompareを試してください@selector(compare :) – Saraswati
'entrydate'は' NSString'か 'NSDate'ですか? – njuri
あなたのデータによって異なります。 'localizedCaseInsensitiveCompare'は' NSString'にのみ適用されます。そのアプリを使用しているときにアプリがクラッシュしない場合、日付は文字列であり、使用する形式を知らなくても対応できません。 – Avi