0

`好的,我正在尝试从我创建的 plist 文件中提取问题和可能的答案

<key>Question1</key>
<string></string>
<key>Answer1</key>
<array/>
<key>4</key>
<string>A</string>
<key>2</key>
<string>B</string>
<key>3</key>
<string>C</string>

所以我试图通过查看各种教程在代码中做到这一点,我只是新手,所以我知道我错了

那么我想将问题放在情节提要中创建的标签中,并与可能的答案相同????`

- (void)viewDidLoad
{
[super viewDidLoad];

NSString *listPath = [[self docDir]stringByAppendingPathComponent:@"work.plist"];
if (![[NSFileManager defaultManager]fileExistsAtPath:listPath]) {
[[NSFileManager defaultManager] copyItemAtPath:[[NSBundle mainBundle]pathForResource:@"work" ofType:@"plist"]toPath:listPath error:nil]; 

} 
NSMutableArray *array = [NSMutableArray arrayWithContentsOfFile:listPath];NSLog(@"count: %i", [array count]);

NSDictionary *temp = (NSDictionary *)[NSPropertyListSerialization
                              propertyListFromData:@"work.plist";
self.firstQuestion = [temp objectForKey:@"Question1"];
self.firstanswer = [NSMutableArray arrayWithArray:[temp objectForKey:@"Answer"]];`
4

1 回答 1

0

也试试这个。

NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsPath = [path objectAtIndex:0];
    NSString *plistpath = [documentsPath stringByAppendingPathComponent:@"question.plist"];
    NSMutableArray *savedStock = [[NSMutableArray alloc] initWithContentsOfFile:plistFilePath];
     for (int i=0; i<[savedStock count]; i++)
        {
            [A-array addObject:[[savedStock objectAtIndex:i] valueForKey:@"A"]];
            [B-array addObject:[[savedStock objectAtIndex:i] valueForKey:@"B"]];
        }
于 2013-04-06T05:05:43.493 回答