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循環結束後它將在範圍內。 – 2012-04-16 20:33:14