終了方法を含めることで問題を解決しました。
If(indexes==0){
endUp = YES;
}
私に正しい方向を示してくれてありがとう。シャッフルの問題ではありませんでした。アレッシン
終了方法を含めることで問題を解決しました。
If(indexes==0){
endUp = YES;
}
私に正しい方向を示してくれてありがとう。シャッフルの問題ではありませんでした。アレッシン
エラーは、最初の配列をシャッフルするために使用するループにある可能性があります。あなたはあなたのコードのその部分を投稿しません...それはこのようなものですか?
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);
}
なるほど、とにかく、わかった!私はそれを終了する1つの'if'ステートメントを実装しました!
if ([indexes count] == 0)
{endProcess = YES}