0
私はIOS/Objective-Cを学習しています。私はすべての質問と回答(ボタンとラベル付き)を表示することができます。しかし、次のステップとしては、ユーザーが答えを入力して右か間違っているかが分かります。私は、インデックスへのユーザーの入力と一致するように思えません。私が何かを書くと、出力は常に "間違っています"。コード:IOS/Objective-C:Array(index)への入力を一致させることができません
#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 *[email protected]"Correct";
NSString *[email protected]"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 *[email protected]"Correct";
NSString *[email protected]"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
私は、インデックスを指定する必要がありますが、私はさまざまな方法で試してみた、それはの助けを借りて、...助け
' question.answer == _ inputAction.text' => '[_inputAction.text isEqualToString question.answer]で作らなければなりません。 "文字列値"ではなく、ポインタを比較しています。 – Larme
[NSString比較の理解](http://stackoverflow.com/questions/3703554/understanding-nsstring-comparison)の可能な複製 – Larme
'_inputAction'は' nil'ですか?あなたのコードはそうでない場合、常に「正解」を出力するようです。 – dan