I´m learning IOS/Objective-C and I have this users input Quizz project; at the moment I can show all questions and answers (with buttons and labels). But as for the next step - user inputs the answer and gets Right or Wrong - something is missing; I cant seem to match the user´s input to the index. If I write something, the output is always "Wrong". The code:
#import "QuizzViewController.h"
#import "Question.h"
@interface QuizzViewController ()
@property (weak, nonatomic) IBOutlet UILabel *questionLabel;
@property (weak, nonatomic) IBOutlet UILabel *answerLabel;
@property NSArray *questions;
@property NSUInteger index;
@property (weak, nonatomic) IBOutlet UILabel *answerValidation;
@property (weak, nonatomic) IBOutlet UITextField *inputAction;
@property (weak, nonatomic) IBOutlet UIButton *answerButton;
@end
@implementation QuizzViewController
- (void)viewDidLoad {
[super viewDidLoad];
_questions = @[
[Question question:@"Best surfer in the World?" answer:@"Kelly Slater"],
[Question question:@"Capital of England?" answer:@"London"],
[Question question:@"Capital of Argentina?" answer:@"Buenos Aires"]
];
_index = -1;
[self nextQuestionAction];
}
- (IBAction)answerAction:(UIButton *)sender {
Question *question = [_questions objectAtIndex:_index];
NSString *correct=@"Correct";
NSString *wrong=@"Wrong";
_inputAction.text=question.answer;
if (question.answer==_inputAction.text){
_answerValidation.text=correct;
}else{
_answerValidation.text=wrong;
}
}
/*- (IBAction)inputAction:(UITextField *)sender {
Question *question = [_questions objectAtIndex:_index];
NSString *correct=@"Correct";
NSString *wrong=@"Wrong";
if (question.answer==_inputAction.text){
_answerValidation.text=correct;
}else{
_answerValidation.text=wrong;
}
}*/
- (IBAction)nextQuestionAction {
_index = (_index + 1) % _questions.count;
Question *question = [_questions objectAtIndex:_index];
_questionLabel.text = question.question;
_answerLabel.text = @"...";
}
- (IBAction)showAnswerAction {
Question *question = [_questions objectAtIndex:_index];
_answerLabel.text = question.answer;
}
@end
I guess I need to point the index, but I've tried in different ways, and it's not working...Thanks for the help