4 つのボタンを使用し、ボタン タグの値をシャッフルして、クリックごとに異なる値を表示します。配列からボタンの値を表示するため、タグの値をシャッフルしようとしているときに次のエラーが発生しました。
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray exchangeObjectAtIndex:withObjectAtIndex:]: index 16 beyond bounds [0 .. 3]'
タグ値の配列をシャッフルするための私のコード、
words = [[NSMutableArray alloc] initWithObjects:@"1", @"2", @"3",@"4", nil] ;
NSUInteger count = [questar count];
for (NSUInteger i = 0; i < count; ++i) {
// Select a random element between i and end of array to swap with.
NSInteger nElements = count - i;
NSInteger n = (arc4random() % nElements) + i;
[words exchangeObjectAtIndex:i withObjectAtIndex:n];
}
どのような変更を加える必要がありますか??誰かが解決するのを手伝ってくれますか?