2011-04-18 9 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]; 

    } 
}  

Je veux charger des données à un tableau, puis les afficher à un tableview (application mac), des suggestions?Comment lire les données plist

+2

Question en double, avez-vous cherché en premier? –

Répondre

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

NSString * plistPath = [[NSBundle mainBundle] pathForResource: @ "ligue" deType: @ "plist"]; contentArray = [NSArray arrayWithContentsOfFile: plistPath]; –

+0

quoi de neuf? ..... – Saurabh

+0

avec ceci je peux obtenir n'importe quoi son mauvais code c'était la première réponse, le problème est quand iam using le tableau je n'obtiens aucun résultat, NSString * filepath = @ "/ Users/agnostos_el/Downloads/PhoneBook/PhoneBook/contacts.txt "; NSDictionary * plistPath = [[NDDictionary alloc] initWithContentsOfFile: chemin de fichier]; NSArray * valeur = [plistPath valueForKey: eponimo_gia_emf.stringValue]; NSString * someObject = [valeur objetAtIndex: 0]; (ou id someObject = [valeur objectAtIndex: 0];) j'obtiens des erreurs quand iam essaye de NSLog (objet) –