Reputation: 778
I am making an iPhone app that will generate something based on quiz answers. I want the button for the answer to change the question text and sometimes the button label text.
Background Info:
Here is the code I am using:
-(IBAction) a
{
questionNumber == 0;
if(questionNumber == 0) {
question.text = @"How Much Do You Use Suppressed Weapons?";
}
questionNumber == 1;
if(questionNumber == 1) {
question.text = @"Do You Like Sleight of Hand?";
answerA.text = @"Yes";
answerB.text = @"No";
[answerC setHidden:YES];
[answerD setHidden:YES];
[answerButton3 setHidden:YES];
[answerButton4 setHidden:YES];
}
}
and this repeats for the other buttons (b,c, and d). I thought it should work, but it doesn't do the "do you like sleight of hand" question. It just stays at the how much do you use suppressed weapons question. Please Help! I really want to get into xcoding for the iphone.
BTW, I am not sure that the tags for this question are correct.
Related Question: How can I have an IBAction that has more than two 'if' statements?
Upvotes: 1
Views: 136
Reputation: 50707
Try using a switch
statement with breaks
.
switch (questionNumber)
{
case 0:
{
question.text = @"How Much Do You Use Suppressed Weapons?";
}
break;
case 1:
{
question.text = @"Do You Like Sleight of Hand?";
answerA.text = @"Yes";
answerB.text = @"No";
[answerC setHidden:YES];
[answerD setHidden:YES];
[answerButton3 setHidden:YES];
[answerButton4 setHidden:YES];
}
break;
}
Upvotes: -1
Reputation: 185681
You're not assigning to questionNumber
. You're comparing.
questionNumber == 1;
That's a noop. It tests if questionNumber
is 1, and then throws away the result. You want
questionNumber = 1;
Upvotes: 2