Disable answer button before first question


#1

Like these guys suggested: viewtopic.php?f=212&t=4431
I found another solution to prevent that the answer button shows an answer before the first question is asked.

In the inspector panel, I added attributes for the ‘disabled’ state of the answer button, with the the text (“Get a question first”) and ‘enabled’ not unchecked.
I selected the ‘Disabled’ state, so that it became the state at opening the app.

I created an outlet/property for the Answer Button:


//answerButton is set to Disabled state in Inspector
@property (weak, nonatomic) IBOutlet UIButton *answerButton;

Now I can access the button properties, and set the state to enabled in the showQuestion: method, so only after the first question is shown, the answer button goes to enabled state.

[code]- (IBAction)showQuestion:(UIButton *)sender {
// Step to next question
currentQuestionIndex ++;
if (currentQuestionIndex == [questions count]) {
currentQuestionIndex = 0;
}
NSString *question = [questions objectAtIndex:currentQuestionIndex];
NSLog(@“Displaying question %@ at index %d”, question, currentQuestionIndex);
[questionField setText];

//
//set answerButton Enabled if it is still in disabled state (this happens only once: before the first question is shown
//
if ([answerButton isEnabled]==NO) {
[answerButton setEnabled:YES];
}
[answerField setText:@"???"];

}

[/code]

It may not be a giant leap for mankind, but I was very very happy that I could think of this solution, AND code it, without hickups. :smiley: