-1

終了方法を含めることで問題を解決しました。

If(indexes==0){
endUp = YES;
}

私に正しい方向を示してくれてありがとう。シャッフルの問題ではありませんでした。アレッシン

4

2 に答える 2

2

エラーは、最初の配列をシャッフルするために使用するループにある可能性があります。あなたはあなたのコードのその部分を投稿しません...それはこのようなものですか?

for (int i=0; i<[indexes count]; i++){
// (...)
        [indexes removeObjectAtIndex:index]; 
// (...)
}

これは良いかもしれません:

int arrayCount = [indexes count];
for (int i=0; i<arrayCount; i++){
// (...)
        [indexes removeObjectAtIndex:index]; 
// (...)
}

この完全なコードは、エラーやクラッシュなしでうまく機能します。

int length = 10; 
NSMutableArray* indexes = [[NSMutableArray alloc] initWithCapacity:length];

for (int i=0; i<10; i++) [indexes addObject:[NSNumber numberWithInt:i]];
NSMutableArray*shuffle = [[NSMutableArray alloc] initWithCapacity:length];


int arrayCount = [indexes count];
for (int i=0; i<arrayCount; i++){

    int index = arc4random()%[indexes count];
    NSLog(@"___index: %i", index);
    NSLog(@"indexes: %@ ", indexes);

    [shuffle addObject:[indexes objectAtIndex:index]];
    [indexes removeObjectAtIndex:index]; 
    NSLog(@"shuffle: %@ ", shuffle);
}


for (int i=0; i<[shuffle count]; i++){
    int questionNumber = [[shuffle objectAtIndex:i] intValue] + 1; 
    NSLog(@"questionNumber: %i ", questionNumber);

}
于 2012-05-08T21:14:09.930 に答える
-1

なるほど、とにかく、わかった!私はそれを終了する1つの'if'ステートメントを実装しました! if ([indexes count] == 0)
{endProcess = YES}

于 2012-05-09T12:42:18.620 に答える