2013-02-11 2 views
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"]];` 

ответ

0

TRY это тоже.

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"]]; 
     } 
Смежные вопросы