我很难理解这个问题。
我正在创建一个测验。在 plist 中有问题......和可能的答案,这是我的 plist
<plist version="1.0">
<dict>
<key>quest</key>
<array/>
<key>Quest1</key>
<string>3234</string>
<key>A</key>
<string>3</string>
<key>B</key>
<string>2</string>
<key>C</key>
<string>1</string>
</dict>
</plist>
数组被调用quest
,我希望能够从代码和 3 个答案中提取“Quest1”......这是我的代码,但我似乎缺少一些东西来让它显示
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [path objectAtIndex:0];
NSString *plistpath = [documentsPath stringByAppendingPathComponent:@"question.plist"];
if(![[NSFileManager defaultManager] fileExistsAtPath:plistpath])
{
plistpath = [[NSBundle mainBundle] pathForResource:@"question" ofType:@"plist"];
}
NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:plistpath];
NSString *errorDesc = nil;
NSPropertyListFormat format;
NSDictionary *temp = (NSDictionary *)[NSPropertyListSerialization propertyListFromData:plistXML mutabilityOption:NSPropertyListMutableContainersAndLeaves format:&format errorDescription:&errorDesc];
if (!temp)
{
NSLog(@"error reading plist: %@, format:%d",errorDesc, format);
}
self.question.text = [temp objectForKey:@"quest"];
self.answer1.text =[temp objectForKey:@"A"];
self.answer2.text =[temp objectForKey:@"B"];
self.answer3.text =[temp objectForKey:@"C"];