我有以下代码,我想用它来检查用户答案并输出分数(满分 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);
}
}
任何帮助将非常感激!非常感谢。