Я предполагаю, что это просто потому, что я очень устал ... но по какой-то причине я не могу заставить мои UIBUTTONS заполняться генерируемыми числами. Числа генерируются случайным образом, за исключением ответа. Я уверен, что это что-то простое. Спасибо!
- (void)determineQ {
first = arc4random() % 1000;
second = arc4random() % 1000;
wrong1 = arc4random() % 1000;
wrong2 = arc4random() % 1000;
wrong3 = arc4random() % 1000;
while (first < second) {
first = arc4random() % 1000;
}
[question setText:[NSString stringWithFormat:@"%d - %d = ?", first, second]];
answer = first - second;
NSLog(@"%d - %d = %d", first, second, answer);
correctLetter = arc4random() % 100;
if (correctLetter <= 25) {
[ans2 setTitle:[NSString stringWithFormat:@"%d", answer] forState:UIControlEventAllEvents];
[ans2 setTitle:[NSString stringWithFormat:@"%d", wrong1] forState:UIControlEventAllEvents];
[ans3 setTitle:[NSString stringWithFormat:@"%d", wrong2] forState:UIControlEventAllEvents];
[ans4 setTitle:[NSString stringWithFormat:@"%d", wrong3] forState:UIControlEventAllEvents];
NSLog(@"The answer is A");
} else if (correctLetter <= 50) {
[ans1 setTitle:[NSString stringWithFormat:@"%d", wrong1] forState:UIControlEventAllEvents];
[ans2 setTitle:[NSString stringWithFormat:@"%d", answer] forState:UIControlEventAllEvents];
[ans3 setTitle:[NSString stringWithFormat:@"%d", wrong2] forState:UIControlEventAllEvents];
[ans4 setTitle:[NSString stringWithFormat:@"%d", wrong3] forState:UIControlEventAllEvents];
NSLog(@"The answer is B");
} else if (correctLetter <= 75) {
[ans1 setTitle:[NSString stringWithFormat:@"%d", wrong1] forState:UIControlEventAllEvents];
[ans2 setTitle:[NSString stringWithFormat:@"%d", wrong2] forState:UIControlEventAllEvents];
[ans3 setTitle:[NSString stringWithFormat:@"%d", answer] forState:UIControlEventAllEvents];
[ans4 setTitle:[NSString stringWithFormat:@"%d", wrong3] forState:UIControlEventAllEvents];
NSLog(@"The answer is C");
} else if (correctLetter <= 100) {
[ans1 setTitle:[NSString stringWithFormat:@"%d", wrong1] forState:UIControlEventAllEvents];
[ans2 setTitle:[NSString stringWithFormat:@"%d", wrong2] forState:UIControlEventAllEvents];
[ans3 setTitle:[NSString stringWithFormat:@"%d", wrong3] forState:UIControlEventAllEvents];
[ans4 setTitle:[NSString stringWithFormat:@"%d", answer] forState:UIControlEventAllEvents];
NSLog(@"The answer is D");
}
}
РЕДАКТИРОВАТЬ: Извините, я случайно поставил UILabels, я имел в виду UIButtons.