2011-04-18 124 views
0
-(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應用程序), 有什麼建議嗎?如何讀取plist數據

+2

重複的問題,你首先搜索? – 2011-04-18 10:58:24

回答

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

NSString * plistPath = [[NSBundle mainBundle] pathForResource:@「league」ofType:@「plist」]; contentArray = [NSArray arrayWithContentsOfFile:plistPath]; – 2011-04-19 08:58:30

+0

這是什麼? ..... – Saurabh 2011-04-19 09:34:53

+0

與此我可以得到任何錯誤的代碼它是第一個答案,問題是當我使用數組我沒有結果,NSString * filepath = @「/ Users/agnostos_el/Downloads/PhoneBook/PhoneBook/contacts.txt「; NSDictionary * plistPath = [[NSDictionary alloc] initWithContentsOfFile:filepath]; NSArray * value = [plistPath valueForKey:eponimo_gia_emf.stringValue]; NSString * someObject = [value objectAtIndex:0]; (或id someObject = [value objectAtIndex:0];)當我試圖NSLog(對象) – 2011-04-19 09:36:42