我有一个问题,我很长时间都在挣扎......请帮助。
我使用以下代码行将记录添加到plist文件中:
[data_appo setObject:@" string value" 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 :(得分: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];
我希望这有帮助!