ランダムにロードされる一連の質問と回答があります。各質問には3つの選択肢があり、私の質問の1つには真と偽があります。
私の質問は、if ステートメントを設定する方法です。私の答えが true または false の場合、最後のボタンは表示されません。
これが私のコードです:
- (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];
}