1

私はアイテム辞書の「日付」キーで配列をソートする必要があります。

mData---------->( { items = ( { Accuracy = 5; Address = "Australia, Sydney CBD, Bridge Street"; Course = "0.00"; Date = "2013-08-20 06:50:28 +0000"; Speed = 3; alt = 0; lat = "-33.8634"; lon = "151.211"; }, { Accuracy = 65; Address = "Armenia, Yerevan, \U053f\U0561\U056c\U0565\U0576\U0581\U056b \U0583\U0578\U0572\U0578\U0581"; Course = "0.00"; Date = "2013-08-20 06:41:02 +0000"; Speed = 3; alt = 1116; lat = "40.20016076"; lon = "44.49ここにコードを入力すると130268"; } ); name = Name; startTime = "10:40"; } ) 、私の配列は 2 のように見えましたNSDictionary * mFirst = [NSDictionary dictionaryWithObjectsAndKeys:[NSDate distantFuture], @"Date", nil]; NSDictionary * mSecond = [NSDictionary dictionaryWithObjectsAndKeys:[NSDate distantPast], @"Date", nil]; NSArray *mArr = [[NSArray alloc]initWithObjects:mFirst,mSecond, nil]; NSDictionary * myDict = [NSDictionary dictionaryWithObject:mArr forKey:@"items"]; NSArray * mSortedArray = [[ NSArray alloc]initWithObjects:myDict, nil]; NSLog(@"%@", mSortedArray);

4

1 に答える 1

0

これを使って:

    NSSortDescriptor *dateDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"Date" ascending:YES] autorelease];
    NSArray *sortDescriptors = [NSArray arrayWithObject:dateDescriptor];
    NSArray *sortedArray = [myArray sortedArrayUsingDescriptors:sortDescriptors];

更新: 私はこれを使用しました:

NSArray *myArray = [[NSArray alloc] initWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:[NSDate distantFuture], @"Date", nil],
        [NSDictionary dictionaryWithObjectsAndKeys:[NSDate distantPast], @"Date", nil], nil];
    NSLog(@"%@", myArray);
    NSSortDescriptor *dateDescriptor = [[NSSortDescriptor alloc] initWithKey:@"Date" ascending:YES];
    NSArray *sortDescriptors = [NSArray arrayWithObject:dateDescriptor];
    NSArray *sortedArray = [myArray sortedArrayUsingDescriptors:sortDescriptors];
    NSLog(@"%@", sortedArray);

そしてログを取得しました:

ソート前: ( { Date = "4001-01-01 00:00:00 +0000"; }, { Date = "0001-12-30 00:00:00 +0000"; } ) ソート後: ( { Date = "0001-12-30 00:00:00 +0000"; }, { Date = "4001-01-01 00:00:00 +0000"; } )

上記のコードを使用しながら確認してください。

于 2013-08-20T07:07:51.300 に答える