0

可能重复: 如何成功写入 plist?

我正在尝试写入 test.plist 文件,该文件存储在我的支持文件中,这是我的代码

- (IBAction)acceptAction:(id)sender {
NSBundle *mainBundle = [NSBundle mainBundle];
NSString *pathToFile = [mainBundle pathForResource:@"test" ofType:@"plist"];
NSMutableDictionary *md = [[NSMutableDictionary alloc] initWithContentsOfFile:pathToFile];
[md setValue:@"yes" forKey:@"hasAgree"];
[md writeToFile:pathToFile atomically:YES];
}


- (IBAction)declineAction:(id)sender {
NSBundle *mainBundle = [NSBundle mainBundle];
NSString *pathToFile = [mainBundle pathForResource:@"test" ofType:@"plist"];
NSMutableDictionary *md = [[NSMutableDictionary alloc] initWithContentsOfFile:pathToFile];
NSString *value;
value = [md objectForKey:@"hasAgree"];
NSLog(@"value is %@", value);
}

接受用于写入的操作按钮..拒绝用于阅读的操作按钮..但根本不起作用,有什么建议吗?

4

1 回答 1

2

你不能在你的包的目录中写。您必须改用文档目录。稍微搜索一下,你就会发现启示。

于 2012-08-14T17:10:46.800 回答