我有 10 个数字(使用 NSMutableArray)随机显示在 10 个不同的标签中。但我需要知道哪个号码对应哪个标签。这些是答案标签,我应该用问题检查它们是否是正确答案。但我应该每次都知道哪个答案在哪里。我怎样才能做到这一点?
任何人都可以帮忙吗?
for (int y=1; y<11; y++) {
NSString *name = [NSString stringWithFormat:@"cevapLabel%d", y];
UILabel *label = [self valueForKey:name];
if (number ==1) {
labelQ.text = [NSString stringWithFormat:@"%ix1=", [[arr objectAtIndex:(random()%9)+1] intValue]];
myMutableArray = [[NSMutableArray alloc] initWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10", nil];
srandom(time(NULL));
NSUInteger count1 = [myMutableArray count];
for (NSUInteger i = 0; i < count1; ++i) {
int nElements = count1 - i;
int n = (random() % nElements) + i;
[myMutableArray exchangeObjectAtIndex: i withObjectAtIndex:n];
}
label.text = [NSString stringWithFormat:@"%i", [[myMutableArray objectAtIndex:y-1] intValue]]; } }
它会持续 10 个其他概率