2012-04-13 24 views
0

我遇到了一個問題,我正在努力尋找很多時間...請幫助。將NSString變量添加到plist文件時出錯

我使用下面的代碼行添加記錄到一個plist文件:

[data_appo的setObject:@ 「字符串值」 forKey:的NSString stringWithFormat:@ 「%i」 的,第(i-1 )]];

它工作正常。現在,如果我嘗試從文件中讀取字符串而不是添加它(我需要用不同的鍵複製值),如下所示:

NSString * string_appo = [data_appo objectForKey:[NSString stringWithFormat:@「%i」 ,J]];

[data_appo setObject:string_appo forKey:[NSString stringWithFormat:@「%i」,(i-1)]]];

然後我武功ERROR_EXEC和應用程序崩潰...

任何想法???

任何幫助將不勝感激

在此先感謝!

回答

0

添加後是否保存了plist文件?我做了很多,我這樣做

 //find the plist file 
     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
     NSString *documentsDirectory = [paths objectAtIndex:0]; 
     NSString *path = [documentsDirectory stringByAppendingPathComponent:@"Notes.plist"]; 
    //set the value for the key 
     [notesData setValue:textView.text forKey:[NSString stringWithFormat:@"General notes %d",selectedIndex]]; 
    //save the plist file 
     [notesData writeToFile: path atomically:YES]; 
    //relese and reload it 
     [notesData release]; 
     notesData = [[NSMutableDictionary alloc] initWithContentsOfFile: path]; 

我希望這有助於!