3

2 つの nsmutablearrays を取得しました。1 つは距離の配列で、もう 1 つはこれらの距離にリンクされた画像を含む配列です。距離配列を昇順で並べ替え、それに基づいて画像配列を並べ替える必要があります。この2つの配列のディクショナリをdistance配列をキーにして作ってみたのですが、distance値が同じ場合、ソートされた画像配列に同じ画像が返ってきます。誰でもこの問題で私を助けることができますか? コードは次のとおりです。

 // Put the two arrays into a dictionary as keys and values
    NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:_locationImages forKeys:_distances];
    // Sort the first array
    NSArray *sortedFirstArray = [[dictionary allKeys] sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
        if ([obj1 floatValue] > [obj2 floatValue])
            return NSOrderedDescending;
        else if ([obj1 floatValue] < [obj2 floatValue])
            return NSOrderedAscending;
        return NSOrderedSame;
    }];
    // Sort the second array based on the sorted first array
    NSArray *sortedSecondArray = [dictionary objectsForKeys:sortedFirstArray notFoundMarker:[NSNull null]];           
4

2 に答える 2