0
私はユーザーの回答を確認し、スコア(5点満点)を出力するために使用したい次のコードを持っています。私は答えを含むplistを使って、それに対してtextField.textをチェックします。私が苦労しているのは、この方法を使ってアウトプット・スコアを合計する方法です。高速列挙中に「スコア」を増やす方法
- (IBAction)checkAnswers:(UITextField *)textField
{
NSString *path2 = [[NSBundle mainBundle] pathForResource:@"7A Cells Microscopes 3" ofType:@"plist"];
NSDictionary *dictionary = [[NSDictionary alloc] initWithContentsOfFile:path2];
NSString *tester = [NSString stringWithFormat:@"%i", textField.tag];
// NSDictionary *secondDict = [dictionary valueForKey:tester];
// NSString *answer = [secondDict valueForKey:@"Answer"];
// if ([textField.text isEqualToString:[[dictionary valueForKey:tester] valueForKey:@"Answer"]]) {
// NSLog(@"YAY");
// }
NSArray *allTextFields = [[NSArray alloc] initWithObjects:eyepiece, objectiveLens, focussingKnobs, stage, mirror, nil];
for (textField in allTextFields) {
int x = 0;
if ([textField.text isEqualToString:[[dictionary valueForKey:tester] valueForKey:@"Answer"]]) {
x++;
NSLog(@"%i", x);
}
}
ご協力いただければ幸いです。 多くのありがとうございます。
forループの上にxを宣言してみてください。その後、forループが終了した後でスコープに入ります。 –