如何阅读plist数据

时间:2011-04-18 10:57:29

标签: objective-c xcode plist

-(void) createPlistFile {
    filepath = @"/Users/agnostos_el/Downloads/PhoneBook/PhoneBook/contacts.txt";
    manager = [NSFileManager defaultManager];
    atomo = [NSMutableDictionary dictionary]; 


    if ( [manager fileExistsAtPath:filepath]==NO)
    {
        NSLog(@"Το Αρχειο Δεν Υπαρχει Το δημειουργω");
        [[NSFileManager defaultManager]createFileAtPath:filepath contents:record attributes:atomo];
    }
    else
    {



    }
}





- (void) times
{
    filepath = @"/Users/agnostos_el/Downloads/PhoneBook/PhoneBook/contacts.txt";

   atomo = [NSMutableDictionary dictionary]; 

    stoixeia = [NSArray arrayWithObjects:onoma.stringValue, eponimo.stringValue,poli.stringValue, odos.stringValue, per.stringValue,tk.stringValue,xora.stringValue,kin.stringValue,kin1.stringValue,kin2.stringValue,kat.stringValue,erg.stringValue,fax.stringValue,email.stringValue,email1.stringValue,email2.stringValue,pros_sel.stringValue,simio.stringValue,nil];

    eponimos = eponimo.stringValue;



    innerDict = [NSDictionary dictionaryWithObjects:
                 [NSArray arrayWithObjects: stoixeia, nil]
                                            forKeys:[NSArray arrayWithObjects:eponimos, nil]];
    [self createPlistFile];  
     pListDict = [NSDictionary dictionaryWithContentsOfFile:filepath];
    [atomo setObject:innerDict forKey:@"eponimo"];

    if ([pListDict count] == 0)
    {

        id plist = [NSPropertyListSerialization dataFromPropertyList:(id)atomo
                                                              format:NSPropertyListXMLFormat_v1_0 errorDescription:nil];        

        record = [[NSData alloc]initWithData:plist];    
        [record writeToFile:filepath atomically:YES];
    }
    else
    if ([pListDict count] >= 1)    
    {
        [pListDict  setObject:atomo forKey:eponimos];
        id plist = [NSPropertyListSerialization dataFromPropertyList:(id)pListDict
                                                              format:NSPropertyListXMLFormat_v1_0 errorDescription:nil];        

        record = [[NSData alloc]initWithData:plist];    
        [record writeToFile:filepath atomically:YES];

    }
}    

我想将数据加载到数组中,然后将它们显示到tableview(mac应用程序), 有什么建议?

1 个答案:

答案 0 :(得分:1)

NSString* plistPath = [[NSBundle mainBundle] pathForResource:@"league" ofType:@"plist"];
contentArray = [NSArray arrayWithContentsOfFile:plistPath];