我是初学者。我看到了像我这样的其他问题,但我有不同的问题。
我有两个问题:
1.我想使用exists label来显示正确的答案。
在这个应用程序中,每个答案后,它只返回图像错误或正确的答案。 没有问题文本和正确答案文本,在通常的测验中如何。 它看起来像在图片上。最后一张图片显示了我在更改后的预期: http://i62.tinypic.com/65ahe0.jpg
我想到改变: - 使用现有标签,首先在问题文本(UIButton * Answer1)下显示图片错误/正确答案下的正确答案。
- 在正确答案文本上显示问题文本。我想我需要改变-QuestionText.hidden,从YES为NO。
它在Simulator中有效。
我在这里读到,arc4random()%只能工作到51。 它会在设备上出现问题吗?
感谢您的帮助。
.m文件:
#import "Game.h"
@interface Game ()
@end
@implementation Game
-(void)RightAnswer{
ScoreNumber = ScoreNumber + 1;
Score.text = [NSString stringWithFormat:@"%i", ScoreNumber];
NextCategory.hidden = NO;
Answer1.hidden = YES;
Answer2.hidden = YES;
Answer3.hidden = YES;
Answer4.hidden = YES;
QuestionText.hidden = YES;
CategorySelected.hidden = YES;
Result.hidden = NO;
Result.image = [UIImage imageNamed:@"rightanswer.png"];
}
-(void)WrongAnswer{
LivesNumber = LivesNumber - 1;
Lives.text = [NSString stringWithFormat:@"%i", LivesNumber];
NextCategory.hidden = NO;
Answer1.hidden = YES;
Answer2.hidden = YES;
Answer3.hidden = YES;
Answer4.hidden = YES;
QuestionText.hidden = YES;
CategorySelected.hidden = YES;
Result.hidden = NO;
Result.image = [UIImage imageNamed:@"wronganswer.png"];
if (LivesNumber == 0) {
Result.image = [UIImage imageNamed:@"gameover.png"];
NextCategory.hidden = YES;
Exit.hidden = NO;
GameInProgress = NO;
}
}
-(IBAction)Answer1:(id)sender{
if (Answer1Correct == YES) {
[self RightAnswer];
}
else{
[self WrongAnswer];
}
}
-(IBAction)Answer2:(id)sender{
if (Answer2Correct == YES) {
[self RightAnswer];
}
else{
[self WrongAnswer];
}
}
-(IBAction)Answer3:(id)sender{
if (Answer3Correct == YES) {
[self RightAnswer];
}
else{
[self WrongAnswer];
}
}
-(IBAction)Answer4:(id)sender{
if (Answer4Correct == YES) {
[self RightAnswer];
}
else{
[self WrongAnswer];
}
}
-(void)Category1{
switch (QuestionSelected) {
case 0:
QuestionText.text = [NSString stringWithFormat:@"What Team Won The 2012/2013 English Football Premier League?"];
[Answer1 setTitle:@"Manchester United" forState:UIControlStateNormal];
[Answer2 setTitle:@"Manchester City" forState:UIControlStateNormal];
[Answer3 setTitle:@"Liverpool" forState:UIControlStateNormal];
[Answer4 setTitle:@"Chelsea" forState:UIControlStateNormal];
Answer1Correct = YES;
break;
case 1:
QuestionText.text = [NSString stringWithFormat:@"Which City Hosted The 1992 Olympic Games?"];
[Answer1 setTitle:@"Norwich" forState:UIControlStateNormal];
[Answer2 setTitle:@"Barcelona" forState:UIControlStateNormal];
[Answer3 setTitle:@"Tokyo" forState:UIControlStateNormal];
[Answer4 setTitle:@"Lisbon" forState:UIControlStateNormal];
Answer2Correct = YES;
break;
case 2:
QuestionText.text = [NSString stringWithFormat:@"By What Score Did England Win The Ashes In The Summer of 2013?"];
[Answer1 setTitle:@"5-0" forState:UIControlStateNormal];
[Answer2 setTitle:@"4-0" forState:UIControlStateNormal];
[Answer3 setTitle:@"3-0" forState:UIControlStateNormal];
[Answer4 setTitle:@"2-0" forState:UIControlStateNormal];
Answer3Correct = YES;
break;
case 3:
QuestionText.text = [NSString stringWithFormat:@"What Team Won The NBA Playoff Finals In 2013?"];
[Answer1 setTitle:@"Golden State Warriors" forState:UIControlStateNormal];
[Answer2 setTitle:@"Memphis Grizzlies" forState:UIControlStateNormal];
[Answer3 setTitle:@"San Antonia Spurs" forState:UIControlStateNormal];
[Answer4 setTitle:@"Miami Heat" forState:UIControlStateNormal];
Answer4Correct = YES;
break;
default:
break;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
if (GameInProgress == NO) {
LivesNumber = 3;
ScoreNumber = 0;
GameInProgress = YES;
}
Result.hidden = YES;
Exit.hidden = YES;
NextCategory.hidden = YES;
Lives.text = [NSString stringWithFormat:@"%i", LivesNumber];
Score.text = [NSString stringWithFormat:@"%i", ScoreNumber];
Answer1Correct = NO;
Answer2Correct = NO;
Answer3Correct = NO;
Answer4Correct = NO;
CategoryLoaded = [[NSUserDefaults standardUserDefaults] integerForKey:@"CategorySaved"];
QuestionSelected = arc4random() %4;
switch (CategoryLoaded) {
case 1:
CategorySelected.text = [NSString stringWithFormat:@"Sport"];
[self Category1];
break;
case 2:
CategorySelected.text = [NSString stringWithFormat:@"Films"];
[self Category2];
break;
case 3:
CategorySelected.text = [NSString stringWithFormat:@"Music"];
[self Category3];
break;
case 4:
CategorySelected.text = [NSString stringWithFormat:@"Games"];
[self Category4];
break;
case 5:
CategorySelected.text = [NSString stringWithFormat:@"Geography"];
[self Category5];
break;
case 6:
CategorySelected.text = [NSString stringWithFormat:@"History"];
[self Category6];
break;
default:
break;
}
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
.h文件:
NSInteger CategoryLoaded; //This has been updated from int as used in the videos, as this is used for saving and loading data. There have been some issue on the later devices using an int for this and not NSInteger
int QuestionSelected;
BOOL Answer1Correct;
BOOL Answer2Correct;
BOOL Answer3Correct;
BOOL Answer4Correct;
int ScoreNumber;
int LivesNumber;
BOOL GameInProgress;
@interface Game : UIViewController
{
IBOutlet UILabel *CategorySelected;
IBOutlet UILabel *QuestionText;
IBOutlet UIButton *Answer1;
IBOutlet UIButton *Answer2;
IBOutlet UIButton *Answer3;
IBOutlet UIButton *Answer4;
IBOutlet UIButton *NextCategory;
IBOutlet UIButton *Exit;
IBOutlet UILabel *Score;
IBOutlet UILabel *Lives;
IBOutlet UIImageView *Result;
}
-(IBAction)Answer1:(id)sender;
-(IBAction)Answer2:(id)sender;
-(IBAction)Answer3:(id)sender;
-(IBAction)Answer4:(id)sender;
-(void)Category1;
-(void)Category2;
-(void)Category3;
-(void)Category4;
-(void)Category5;
-(void)Category6;
-(void)RightAnswer;
-(void)WrongAnswer;
@end
答案 0 :(得分:0)
1-我无法理解,你能详细说明吗?
2-不会在你指定的任何范围内正常工作,但请注意,如果你需要生成介于0到89之间的随机数(包含0到89),你需要将它设为arc4random() %90;