-1

我的项目中有一个 Plist 文件,其中包含许多不同的数组;每个数组是一个不同的类别,然后包含针对单个问题的附加数组。我遇到的问题是访问这些数组中的节点及其值。

我正在使用的代码:

-(IBAction)nextleft {

    if (questionCounter > 1) {
        questionCounter -= 1;
    }

    [self nextQuestion];

}

-(IBAction)nextright {

    if (questionCounter < 20) {
        questionCounter += 1;
    }

    [self nextQuestion];

}

-(void)nextQuestion {

    NSArray *pair;

    pair = [categories objectAtIndex:questionCounter]; 

    plistQuestion = [pair objectAtIndex:0];
    plistAnswer = [pair objectAtIndex:1];

    abbreviation.text = plistQuestion;

}

我的类别数组是从我的 Plist 文件中用这一行填充的;

categories = [NSArray arrayWithContentsOfFile:@"questions.plist"];
4

2 回答 2

1

您可以创建一个类,其中有两个 NSString 实例(问题和答案),它们包含问题和答案的值。创建一个由该类的对象组成的类别数组。

于 2012-08-09T17:38:13.510 回答
0

解决方案:

NSArray *categories = [NSArray arrayWithContentsOfFile:@"questions.plist"];

for (NSArray *pair in categories)
{
    NSString *q = [pair objectAtIndex:0];
    NSString *a = [pair objectAtIndex:1];

    // process q and a
}
于 2012-08-07T17:34:43.480 回答