我有一个用于存储问题和答案数据的属性列表文件。在这个文件中,我有一组数组,在这些数组中我存储了不同的类别和问题。但是我似乎无法访问这些数据?
属性文件;
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Category1</key>
<array>
<array>
<string>Question1</string>
<string>Answer1</string>
</array>
<array>
<string>Question2</string>
<string>Answer2</string>
</array>
<array>
<string>Question3</string>
<string>Answer3</string>
</array>
<array>
<string>Question4</string>
<string>Answer4</string>
</array>
</array>
</dict>
</plist>
下面我使用两个简单的按钮来访问属性列表文件;
-(IBAction)nextleft {
[self bingsound];
if (questionCounter > 1) {
questionCounter -= 1;
}
[self nextQuestion];
}
-(IBAction)nextright {
[self bingsound];
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;
}
我正在填充类别数组,如下所示;
categories = [NSArray arrayWithContentsOfFile:@"questions.plist"];