1

コア データ アプリケーションを開発しています。新規、受諾、配達済みなど、さまざまなステータスの注文を表示するメイン テーブルがあります。

私が抱えている問題は、各セクションを異なる基準で注文する必要があることです。例えば:

  • 新しい注文は、古いものから順に並べる必要があります。
  • 受け入れられた注文は、一番上に配達されるように、最も早い順に並べ替える必要があります。
  • 配送された注文は、最新のものから上に並べ替える必要があります。

結果を取得するときのコードは次のとおりです。

NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"CDOrder"];
request.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"orderPosition" ascending:YES],[NSSortDescriptor sortDescriptorWithKey:@"createdDate" ascending:NO]];  

User* user = [User getInstance];
NSDate *TwelveHoursAgo = [NSDate dateWithTimeIntervalSinceNow:-3600 * 12];

request.predicate = [NSPredicate predicateWithFormat:@"(servicePersonId == %@) AND (createdDate >= %@)", [NSNumber numberWithLong:user.userId], TwelveHoursAgo];
ordersTableViewController.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:super.managedObjectContext sectionNameKeyPath:@"orderPosition" cacheName:nil];

ご覧のとおり、これは に基づいてセクションを作成し"orderPosition"、すべての注文を で並べ替えてい"createdDate"ます。しかし、特定の注文を注文する必要があります"deliverDate"

ありがとう

4

1 に答える 1