我認爲這只是因爲我很累..但由於某種原因,我無法讓我的UIBUTTONS充滿了生成的數字。除答案外,這些數字是隨機生成的。我相信這很簡單。謝謝!iPhone - 無法將int放入UIButton
- (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。
你會得到什麼錯誤?不是'first'和'second'是一個float,因此應該是'[question setText:[NSString stringWithFormat:@「%。0f - %.0f =?」,first,second]];' – simonbs
第一個和第二個是實際上是整數。 –