0

したがって、ここには3つの異なるアレイが含まれています...

私はgolferThreeIcons(NSMutableArray)をループしていて、最高の4つの結果(golferThreeIconsには文字列として#が含まれています)を取得してtopFourIconsNum(NSMutableArray)に格納しようとしています。次に、その最高のIDを格納する予定です。配列topFourIconsId(NSMutableArray)の番号。

トリッキーなことの1つは、golferThreeIconsが99から始まることですが、それをゼロのように動作させたいと思います。したがって、99という数字はどちらの配列にも追加されるべきではありません...

例:golferThreeIcons {2,1,5,3,9}

そして、ループが通過した後、私はそれがこのようなものを表示したいです...

topFourIconsId {0,2,3,4}---0はゴルファーの2に対応ThreeIcons---2はゴルファーの5に対応3アイコン

topFourIconsNum {2,5,3,9} ----(上位4つのアイコンIDに対応する限り任意の順序)

NSMutableArray *topFourIconsId = [NSMutableArray arrayWithObjects: @"0", @"0", @"0", @"0", @"0" ,nil];
NSMutableArray *topFourIconsNum = [NSMutableArray arrayWithObjects: @"0", @"0", @"0", @"0", @"0" ,nil];
int *ids = 0;
                for (NSString *s in golferThreeIconCounter) {
                    if(s != @"0") {
                        int sint = [s intValue];
                        int *idn = 0;
                        for(NSString *n in topFourIconsNum) {
                            int nint= [n intValue];
                            if(sint == 99 && nint == 0) {
                                NSString *idstring = [NSString stringWithFormat:@"%d", ids];
                                NSString *sintstring = [NSString stringWithFormat:@"%d", sint];
                                [topFourIconsId replaceObjectAtIndex:idn withObject:idstring];
                                [topFourIconsNum replaceObjectAtIndex:idn withObject:sintstring];
                                NSLog(@"IN %@",sintstring);
                                break;
                            }
                            else {
                                if (sint > nint) {
                                    NSString *idstring = [NSString stringWithFormat:@"%d", ids];
                                    NSString *sintstring = [NSString stringWithFormat:@"%d", sint];
                                    [topFourIconsId replaceObjectAtIndex:idn withObject:idstring];
                                    [topFourIconsNum replaceObjectAtIndex:idn withObject:sintstring];
                                    NSLog(@"IN %@",sintstring);
                                    break;
                                }
                            }
                            idn++;
                        }
                    }
                    ids++;
                }
4

1 に答える 1

0

ただのクレイジーなアイデア

配列インデックスをキーとして、配列値を値としてNSDictionaryにgolferThreeIconsを配置し、その値でキーを並べ替えます。

NSDictionary *dict = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"2", @"1", @"5", @"3", @"9", nil] forKeys:[NSArray arrayWithObjects:@"0", @"1", @"2", @"3", @"4", nil]];
NSArray *sortedKeys = [dict keysSortedByValueUsingSelector:@selector(caseInsensitiveCompare:)];

NSLog([sortedKeys description]);
于 2012-05-23T11:31:49.070 に答える