我的项目中有一个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"];
答案 0 :(得分:1)
您可以创建一个类,其中有两个NSString实例(问题与答案),其中包含问题与答案的值。 answer.Create一个由该类对象组成的类别数组。
答案 1 :(得分: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
}