我有一系列随机加载的问题和答案,每个问题有 3 个选择,在我的一个问题中,我只有对与错,
我的问题是如何设置我的 if 语句,如果我的答案是真或假,不要显示最后一个按钮,
这是我的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
NSString *qOne = @"Question 1";
NSString *qTwo = @"Question 2";
NSString *qThree = @"Question 3";
NSString *qFour = @"Question 4";
NSString *answerOne = @"Après le souper";
NSString *answerTwo = @"1";
NSString *answerThree = @" Holstein";
NSString *answerFour = @" yes";
NSString *answer2One = @"Après un exercice physique";
NSString *answer2Two = @" 2";
NSString *answer2Three = @" Jersey";
NSString *answer2Four = @" No";
NSString *answer3One = @"Avant un exercice physique";
NSString *answer3Two = @" 4";
NSString *answer3Three = @" Canadienne";
我想删除这部分 NSString *answer3Four = @" ";
NSString *correctOne = @"Après un exercice physique";
NSString *correctTwo = @" 4";
NSString *correctThree = @" Yes";
NSString *correctFour = @" 14";
answerComments = [[NSArray alloc] initWithObjects: answerOne, answerTwo, answerThree, answerFour, nil];
answer2Comments = [[NSArray alloc] initWithObjects: answer2One, answer2Two, answer2Three, answer2Four, nil];
answer3Comments = [[NSArray alloc] initWithObjects: answer3One, answer3Two, answer3Three, answer3Four,nil];
qComments = [[NSArray alloc] initWithObjects:qOne, qTwo, qThree, qFour, nil];
correctComments = [[NSArray alloc] initWithObjects: correctOne, correctTwo, correctThree, correctFour, nil];
// A random string is selected and assigned to artist.
int rand = arc4random()%4;
NSString *artist = [qComments objectAtIndex:rand];
firstAnswer = [answerComments objectAtIndex:rand];
secondAnswer = [answer2Comments objectAtIndex:rand];
threeAnswer = [answer3Comments objectAtIndex:rand];
correct = [correctComments objectAtIndex:rand];
NSLog (@"%@",correct);
// Here's the problematic code:
[question setText:(artist)];
[question setFont:[UIFont fontWithName:@"HelveticaRoundedLTStd-Bd" size:42]];
question.adjustsFontSizeToFitWidth = NO;
question.numberOfLines = 0;
[test setTitle:(firstAnswer) forState:UIControlStateNormal];
[test setBackgroundImage:[UIImage imageNamed:@"activeBtn.png"] forState:UIControlStateHighlighted];
[ansONE setTitle:(secondAnswer) forState:UIControlStateNormal];
[ansONE setBackgroundImage:[UIImage imageNamed:@"activeBtn.png"] forState:UIControlStateHighlighted];
ansTWO = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[ansTWO addTarget:self
action:@selector(ansTWO:)
forControlEvents:UIControlEventTouchDown];
[ansTWO setTitle:(threeAnswer) forState:UIControlStateNormal];
[ansTWO setBackgroundImage:[UIImage imageNamed:@"activeBtn.png"] forState:UIControlStateHighlighted];
ansTWO.titleLabel.font = [UIFont fontWithName:@"HelveticaRoundedLTStd-Bd" size:24];
[ansTWO setTitleColor:[UIColor colorWithRed:21/255.0 green:119/255.0 blue:183/255.0 alpha:.77] forState:UIControlStateNormal];
ansTWO.titleLabel.textAlignment = UITextAlignmentCenter;
[ansTWO setTag:2];
UIImage *buttonImage = [UIImage imageNamed:@"quizBtn.png"];
[ansTWO setBackgroundImage:buttonImage forState:UIControlStateNormal];
ansTWO.frame = CGRectMake(243, 586,549, 56);
[self.view addSubview:ansTWO];
}