iphone - How can I have an IBAction that has more than two 'if' statements? -


i creating quiz app display depending on results of quiz. right stuck @ something. quiz app simple, 4 answers, , question. having each button switch view next question seemed code, came this. if each button, when pressed, change question , answers? how this? right now, code answer 'a' goes this:

-(ibaction)a {  switch(questionnumber) {     case 0:     {         question.text = @"how use suppressed weapons?";     }         break;      case 1:      {         question.text = @"do sleight of hand?";          answera.text = @"yes";         answerb.text = @"no";         [answerc sethidden:yes];         [answerd sethidden:yes];         [answerbutton3 sethidden:yes];         [answerbutton4 sethidden:yes];     }         break; } 

}

this isn't working, hoping go 'if' statement path. how code each letter answer? thinking this:

-(ibaction)a { if(questionnumber = 0) { question.text = @"whatever question is";

and after each question add 1 question number. , next time pressed, change question text else, , change labels letter answers. appreciated. thank you!!!

related question: having more 1 if statements in 1 ibaction in .m file isn't working

a switch statement should fine trying do, syntax little off, use this:

-(ibaction)a {      switch(questionnumber)     {         case 0:             question.text = @"how use suppressed weapons?";             break;         case 1:             question.text = @"do sleight of hand?";             answera.text = @"yes";             answerb.text = @"no";             [answerc sethidden:yes];             [answerd sethidden:yes];             [answerbutton3 sethidden:yes];             [answerbutton4 sethidden:yes];             break;        default:             break;     } } 

a example of can found here: http://www.techotopia.com/index.php/the_objective-c_switch_statement


however, think better choice make question object has properties need , have array of in correct order. need pull question out index (questionnumber) , map each property interface. go far store values in plist , read in can edit/add questions on fly without having hardcode anything.

here quick tutorial reading plist nsarray. second example of using nsdictionary objects might simplest you. each dictionary question appropriate properties. can pull values out of dictionary (which pulled array index).


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -