我是iphone开发的新手,我正在使用下面的代码将值添加到plist中,但是当执行代码后检查plist时,我看不到任何保存在plist.Where中的值,我出错了吗?请帮助我,我已经创建的plist在资源folder.Thanks中。
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"regvalue.plist"];
NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:finalPath];
[plistDict setValue:@"hello" forKey:@"choice"];
[plistDict writeToFile:finalPath atomically: YES];用于检索值
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"regvalue.plist"];
NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:finalPath];
NSString *value;
value = [plistDict objectForKey:@"choice"];
NSLog(@"the value is %@",value);它只给出空的帮助我out.Thanks。
发布于 2010-04-12 19:11:38
资源文件夹不可写。您应该将其保存到documents文件夹中。
发布于 2012-11-02 20:08:43
也许你可以在这里找到答案:How to write data in plist?
但是,如果你只想在你的应用程序中保存一些消息,NSUserDefaults是更好的方法。
https://stackoverflow.com/questions/2621515
复制相似问题